This commit is contained in:
Wang Kejun 2022-06-20 15:16:39 +08:00
parent 9ce514a8bf
commit 2f1444aac4
17 changed files with 175 additions and 84 deletions

View File

@ -24,6 +24,6 @@ export declare class DebugStore<ED extends EntityDict, Cxt extends Context<ED>>
registerTrigger<T extends keyof ED>(trigger: Trigger<ED, T, Cxt>): void; registerTrigger<T extends keyof ED>(trigger: Trigger<ED, T, Cxt>): void;
registerChecker<T extends keyof ED>(checker: Checker<ED, T, Cxt>): void; registerChecker<T extends keyof ED>(checker: Checker<ED, T, Cxt>): void;
startInitializing(): void; startInitializing(): void;
endInitalizing(): void; endInitializing(): void;
} }
export {}; export {};

View File

@ -85,7 +85,7 @@ class DebugStore extends oak_memory_tree_store_1.TreeStore {
startInitializing() { startInitializing() {
this.rwLock.acquire('X'); this.rwLock.acquire('X');
} }
endInitalizing() { endInitializing() {
this.rwLock.release(); this.rwLock.release();
} }
} }

View File

@ -22,10 +22,10 @@ async function initDataInStore(store, createContext, initialData) {
} }
await context.commit(); await context.commit();
} }
store.endInitalizing(); store.endInitializing();
} }
function getMaterializedData() { function getMaterializedData() {
if ( /* process.env.OAK_PLATFORM === 'weChatMp' */true) { if (process.env.OAK_PLATFORM === 'weChatMp') {
try { try {
const data = wx.getStorageSync('debugStore'); const data = wx.getStorageSync('debugStore');
const stat = wx.getStorageSync('debugStoreStat'); const stat = wx.getStorageSync('debugStoreStat');
@ -41,10 +41,26 @@ function getMaterializedData() {
return; return;
} }
} }
else if (process.env.OAK_PLATFORM === 'web') {
try {
const data = JSON.parse(window.localStorage.getItem('debugStore'));
const stat = JSON.parse(window.localStorage.getItem('debugStoreStat'));
if (data && stat) {
return {
data,
stat,
};
}
return;
}
catch (e) {
return;
}
}
} }
let lastMaterializedVersion = 0; let lastMaterializedVersion = 0;
function materializeData(data, stat) { function materializeData(data, stat) {
if ( /* process.env.OAK_PLATFORM === 'weChatMp' */true) { if (process.env.OAK_PLATFORM === 'weChatMp') {
try { try {
wx.setStorageSync('debugStore', data); wx.setStorageSync('debugStore', data);
wx.setStorageSync('debugStoreStat', stat); wx.setStorageSync('debugStoreStat', stat);
@ -62,6 +78,18 @@ function materializeData(data, stat) {
}); });
} }
} }
else if (process.env.OAK_PLATFORM === 'web') {
try {
window.localStorage.setItem('debugStore', typeof data === 'string' ? data : JSON.stringify(data));
window.localStorage.setItem('debugStoreStat', JSON.stringify(stat));
lastMaterializedVersion = stat.commit;
alert('数据已物化');
}
catch (e) {
console.error(e);
alert('物化数据失败');
}
}
} }
/** /**
* 在debug环境上创建watcher * 在debug环境上创建watcher

View File

@ -25,9 +25,3 @@ __exportStar(require("./types/Feature"), exports);
__exportStar(require("./types/ExceptionRoute"), exports); __exportStar(require("./types/ExceptionRoute"), exports);
__exportStar(require("./features/cache"), exports); __exportStar(require("./features/cache"), exports);
__exportStar(require("./features/upload"), exports); __exportStar(require("./features/upload"), exports);
/* export {
initI18nWechatMp,
getI18nInstanceWechatMp,
I18nWechatMpRuntimeBase,
I18nWechatMp,
} from './platforms/wechatMp/i18n'; */

View File

@ -37,16 +37,16 @@ function createAspectProxy(storageSchema, createContext, triggers, checkers, wat
return async (params, scene) => { return async (params, scene) => {
const runningContext = createContext(debugStore, scene); const runningContext = createContext(debugStore, scene);
await runningContext.begin(); await runningContext.begin();
let aspectCompeleted = false; let aspectCompleted = false;
try { try {
const result = await aspect(params, runningContext); const result = await aspect(params, runningContext);
await runningContext.commit(); await runningContext.commit();
aspectCompeleted = true; aspectCompleted = true;
await features.cache.sync(runningContext.opRecords); await features.cache.sync(runningContext.opRecords);
return result; return result;
} }
catch (err) { catch (err) {
if (!aspectCompeleted) { if (!aspectCompleted) {
await runningContext.rollback(); await runningContext.rollback();
} }
if (err instanceof types_1.OakRowInconsistencyException) { if (err instanceof types_1.OakRowInconsistencyException) {

View File

@ -25,6 +25,11 @@ export declare class I18nWechatMpRuntimeBase implements CommonI18nInterface {
t(key: string, options?: object): string; t(key: string, options?: object): string;
getFallbackLocale(): string; getFallbackLocale(): string;
} }
declare global {
const OakI18n: {
i18nInstance: I18nWechatMpRuntimeBase | null;
};
}
export declare function initI18nWechatMp(options: { export declare function initI18nWechatMp(options: {
locales: Locales; locales: Locales;
defaultLocale?: string; defaultLocale?: string;

View File

@ -12,7 +12,7 @@ class I18nWechatMpRuntimeBase {
translations; translations;
currentLocale; currentLocale;
fallbackLocale; fallbackLocale;
constructor(translations = {}, currentLocale = "zh_CN" /* Locale.default */, fallbackLocale = "zh_CN" /* Locale.default */) { constructor(translations = {}, currentLocale = "zh_CN" /* default */, fallbackLocale = "zh_CN" /* default */) {
this.translations = translations; this.translations = translations;
this.currentLocale = currentLocale; this.currentLocale = currentLocale;
this.fallbackLocale = fallbackLocale; this.fallbackLocale = fallbackLocale;

View File

@ -1,10 +1,4 @@
/// <reference types="wechat-miniprogram" /> /// <reference types="wechat-miniprogram" />
/// <reference types="wechat-miniprogram" />
/// <reference types="wechat-miniprogram" />
/// <reference types="wechat-miniprogram" />
/// <reference types="wechat-miniprogram" />
/// <reference types="wechat-miniprogram" />
/// <reference types="wechat-miniprogram" />
import './polyfill'; import './polyfill';
import { Aspect, Checker, Context, EntityDict, RowStore, StorageSchema, Trigger, ActionDictOfEntityDict, DeduceSorterItem, DeduceOperation, SelectRowShape, Watcher } from "oak-domain/lib/types"; import { Aspect, Checker, Context, EntityDict, RowStore, StorageSchema, Trigger, ActionDictOfEntityDict, DeduceSorterItem, DeduceOperation, SelectRowShape, Watcher } from "oak-domain/lib/types";
import { Feature } from '../../types/Feature'; import { Feature } from '../../types/Feature';
@ -13,6 +7,8 @@ import { BasicFeatures } from "../../features";
import { ExceptionRouters } from '../../types/ExceptionRoute'; import { ExceptionRouters } from '../../types/ExceptionRoute';
import { NamedFilterItem, NamedSorterItem } from '../../types/NamedCondition'; import { NamedFilterItem, NamedSorterItem } from '../../types/NamedCondition';
import { CreateNodeOptions } from '../../features/runningTree'; import { CreateNodeOptions } from '../../features/runningTree';
import { initI18nWechatMp, I18nWechatMpRuntimeBase, getI18nInstanceWechatMp } from './i18n/index';
export { initI18nWechatMp, getI18nInstanceWechatMp, I18nWechatMpRuntimeBase, };
declare type RowSelected<ED extends EntityDict, T extends keyof ED, Proj extends ED[T]['Selection']['data'] = Required<ED[T]['Selection']['data']>> = SelectRowShape<ED[T]['Schema'], Proj> | undefined; declare type RowSelected<ED extends EntityDict, T extends keyof ED, Proj extends ED[T]['Selection']['data'] = Required<ED[T]['Selection']['data']>> = SelectRowShape<ED[T]['Schema'], Proj> | undefined;
declare type OakComponentOption<ED extends EntityDict, T extends keyof ED, Cxt extends Context<ED>, AD extends Record<string, Aspect<ED, Cxt>>, FD extends Record<string, Feature<ED, Cxt, AD>>, FormedData extends WechatMiniprogram.Component.DataOption, IsList extends boolean> = { declare type OakComponentOption<ED extends EntityDict, T extends keyof ED, Cxt extends Context<ED>, AD extends Record<string, Aspect<ED, Cxt>>, FD extends Record<string, Feature<ED, Cxt, AD>>, FormedData extends WechatMiniprogram.Component.DataOption, IsList extends boolean> = {
entity: T; entity: T;
@ -159,4 +155,3 @@ export declare function initialize<ED extends EntityDict, Cxt extends Context<ED
declare type OakWechatMpOptions<TData extends WechatMiniprogram.Component.DataOption, TProperty extends WechatMiniprogram.Component.PropertyOption, TMethod extends WechatMiniprogram.Component.MethodOption, InherentProperties extends WechatMiniprogram.Component.PropertyOption, InherentMethods extends WechatMiniprogram.Component.MethodOption, InherentData extends WechatMiniprogram.Component.DataOption, InherentInstanceProperty extends WechatMiniprogram.IAnyObject, TCustomInstanceProperty extends WechatMiniprogram.IAnyObject = {}, TIsPage extends boolean = false> = Partial<TData> & Partial<WechatMiniprogram.Component.Property<TProperty>> & Partial<WechatMiniprogram.Component.Method<TMethod, TIsPage>> & Partial<WechatMiniprogram.Component.OtherOption> & Partial<WechatMiniprogram.Component.Lifetimes> & ThisType<WechatMiniprogram.Component.Instance<TData & InherentData, TProperty & InherentProperties, TMethod & InherentMethods, TCustomInstanceProperty & InherentInstanceProperty, TIsPage>>; declare type OakWechatMpOptions<TData extends WechatMiniprogram.Component.DataOption, TProperty extends WechatMiniprogram.Component.PropertyOption, TMethod extends WechatMiniprogram.Component.MethodOption, InherentProperties extends WechatMiniprogram.Component.PropertyOption, InherentMethods extends WechatMiniprogram.Component.MethodOption, InherentData extends WechatMiniprogram.Component.DataOption, InherentInstanceProperty extends WechatMiniprogram.IAnyObject, TCustomInstanceProperty extends WechatMiniprogram.IAnyObject = {}, TIsPage extends boolean = false> = Partial<TData> & Partial<WechatMiniprogram.Component.Property<TProperty>> & Partial<WechatMiniprogram.Component.Method<TMethod, TIsPage>> & Partial<WechatMiniprogram.Component.OtherOption> & Partial<WechatMiniprogram.Component.Lifetimes> & ThisType<WechatMiniprogram.Component.Instance<TData & InherentData, TProperty & InherentProperties, TMethod & InherentMethods, TCustomInstanceProperty & InherentInstanceProperty, TIsPage>>;
export declare type MakeOakPage<ED extends EntityDict, Cxt extends Context<ED>, AD extends Record<string, Aspect<ED, Cxt>>, FD extends Record<string, Feature<ED, Cxt, AD>>> = <T extends keyof ED, D extends WechatMiniprogram.Component.DataOption, P extends WechatMiniprogram.Component.PropertyOption, M extends WechatMiniprogram.Component.MethodOption, Proj extends ED[T]['Selection']['data'], IsList extends boolean, IS extends WechatMiniprogram.IAnyObject = {}, FormedData extends WechatMiniprogram.Component.DataOption = {}>(options: OakPageOption<ED, T, Cxt, AD, FD, Proj, FormedData, IsList> & ThisType<WechatMiniprogram.Component.Instance<D & OakPageData, P & OakPageProperties, M & OakPageMethods<ED, T>, IS & OakPageInstanceProperties<ED, Cxt, AD, FD>, true>>, componentOptions: OakWechatMpOptions<D, P, M, OakPageProperties, OakPageMethods<ED, T>, OakPageData & FormedData, OakPageInstanceProperties<ED, Cxt, AD, FD>, IS, true>) => string; export declare type MakeOakPage<ED extends EntityDict, Cxt extends Context<ED>, AD extends Record<string, Aspect<ED, Cxt>>, FD extends Record<string, Feature<ED, Cxt, AD>>> = <T extends keyof ED, D extends WechatMiniprogram.Component.DataOption, P extends WechatMiniprogram.Component.PropertyOption, M extends WechatMiniprogram.Component.MethodOption, Proj extends ED[T]['Selection']['data'], IsList extends boolean, IS extends WechatMiniprogram.IAnyObject = {}, FormedData extends WechatMiniprogram.Component.DataOption = {}>(options: OakPageOption<ED, T, Cxt, AD, FD, Proj, FormedData, IsList> & ThisType<WechatMiniprogram.Component.Instance<D & OakPageData, P & OakPageProperties, M & OakPageMethods<ED, T>, IS & OakPageInstanceProperties<ED, Cxt, AD, FD>, true>>, componentOptions: OakWechatMpOptions<D, P, M, OakPageProperties, OakPageMethods<ED, T>, OakPageData & FormedData, OakPageInstanceProperties<ED, Cxt, AD, FD>, IS, true>) => string;
export declare type MakeOakComponent<ED extends EntityDict, Cxt extends Context<ED>, AD extends Record<string, Aspect<ED, Cxt>>, FD extends Record<string, Feature<ED, Cxt, AD>>> = <T extends keyof ED, D extends WechatMiniprogram.Component.DataOption, P extends WechatMiniprogram.Component.PropertyOption, M extends WechatMiniprogram.Component.MethodOption, IsList extends boolean, IS extends WechatMiniprogram.IAnyObject = {}, FormedData extends WechatMiniprogram.Component.DataOption = {}>(options: OakComponentOption<ED, T, Cxt, AD, FD, FormedData, IsList> & ThisType<WechatMiniprogram.Component.Instance<D & OakPageData, P & OakPageProperties, M & OakPageMethods<ED, T>, IS & OakPageInstanceProperties<ED, Cxt, AD, FD>, true>>, componentOptions: OakWechatMpOptions<D, P, M, OakComponentProperties, OakComponentMethods<ED, T>, OakComponentData & FormedData, OakComponentInstanceProperties<ED, Cxt, AD, FD>, IS, false>) => string; export declare type MakeOakComponent<ED extends EntityDict, Cxt extends Context<ED>, AD extends Record<string, Aspect<ED, Cxt>>, FD extends Record<string, Feature<ED, Cxt, AD>>> = <T extends keyof ED, D extends WechatMiniprogram.Component.DataOption, P extends WechatMiniprogram.Component.PropertyOption, M extends WechatMiniprogram.Component.MethodOption, IsList extends boolean, IS extends WechatMiniprogram.IAnyObject = {}, FormedData extends WechatMiniprogram.Component.DataOption = {}>(options: OakComponentOption<ED, T, Cxt, AD, FD, FormedData, IsList> & ThisType<WechatMiniprogram.Component.Instance<D & OakPageData, P & OakPageProperties, M & OakPageMethods<ED, T>, IS & OakPageInstanceProperties<ED, Cxt, AD, FD>, true>>, componentOptions: OakWechatMpOptions<D, P, M, OakComponentProperties, OakComponentMethods<ED, T>, OakComponentData & FormedData, OakComponentInstanceProperties<ED, Cxt, AD, FD>, IS, false>) => string;
export {};

View File

@ -3,13 +3,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod }; return (mod && mod.__esModule) ? mod : { "default": mod };
}; };
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.initialize = void 0; exports.initialize = exports.I18nWechatMpRuntimeBase = exports.getI18nInstanceWechatMp = exports.initI18nWechatMp = void 0;
require("./polyfill"); require("./polyfill");
const types_1 = require("oak-domain/lib/types"); const types_1 = require("oak-domain/lib/types");
const initialize_1 = require("../../initialize"); const initialize_1 = require("../../initialize");
const assert_1 = __importDefault(require("assert")); const assert_1 = __importDefault(require("assert"));
const lodash_1 = require("lodash"); const lodash_1 = require("lodash");
const index_1 = require("./i18n/index"); const index_1 = require("./i18n/index");
Object.defineProperty(exports, "initI18nWechatMp", { enumerable: true, get: function () { return index_1.initI18nWechatMp; } });
Object.defineProperty(exports, "I18nWechatMpRuntimeBase", { enumerable: true, get: function () { return index_1.I18nWechatMpRuntimeBase; } });
Object.defineProperty(exports, "getI18nInstanceWechatMp", { enumerable: true, get: function () { return index_1.getI18nInstanceWechatMp; } });
; ;
function callPicker(features, attr, params, entity, parent) { function callPicker(features, attr, params, entity, parent) {
const relation = features.cache.judgeRelation(entity, attr); const relation = features.cache.judgeRelation(entity, attr);
@ -479,11 +482,15 @@ function createPageOptions(options, doSubscribe, features, exceptionRouterDict)
oakEntity: node.getEntity(), oakEntity: node.getEntity(),
oakFullpath: path2, oakFullpath: path2,
oakFrom, oakFrom,
newOakActions: oakActions && JSON.parse(oakActions).length > 0 ? JSON.parse(oakActions) : options.actions || [], newOakActions: oakActions && JSON.parse(oakActions).length > 0
? JSON.parse(oakActions)
: options.actions || [],
}, () => {
this.isReady = true;
if (this.isReady) {
this.refresh();
}
}); });
if (this.isReady) {
this.refresh();
}
}, },
...makeComponentMethods(features, doSubscribe, formData, exceptionRouterDict), ...makeComponentMethods(features, doSubscribe, formData, exceptionRouterDict),
}, },
@ -524,7 +531,7 @@ function createPageOptions(options, doSubscribe, features, exceptionRouterDict)
}; };
return componentOptions; return componentOptions;
} }
function createComponentOptions(options, features, doSubscribe, exceptionRouterDict) { function createComponentOptions(options, doSubscribe, features, exceptionRouterDict) {
const { formData, entity } = options; const { formData, entity } = options;
const componentOptions = { const componentOptions = {
properties: { properties: {
@ -533,21 +540,25 @@ function createComponentOptions(options, features, doSubscribe, exceptionRouterD
oakParent: String, oakParent: String,
}, },
observers: { observers: {
"oakPath": function (path) { oakPath: function (path) {
return this.onPropsChanged({ return this.onPropsChanged({
path, path,
}); });
}, },
"oakParent": function (parent) { oakParent: function (parent) {
return this.onPropsChanged({ return this.onPropsChanged({
parent, parent,
}); });
} },
}, },
methods: { methods: {
async onPropsChanged(options) { async onPropsChanged(options) {
const path2 = options.hasOwnProperty('path') ? options.path : this.data.oakPath; const path2 = options.hasOwnProperty('path')
const parent2 = options.hasOwnProperty('parent') ? options.parent : this.data.oakParent; ? options.path
: this.data.oakPath;
const parent2 = options.hasOwnProperty('parent')
? options.parent
: this.data.oakParent;
if (path2 && parent2) { if (path2 && parent2) {
const oakFullpath2 = `${parent2}.${path2}`; const oakFullpath2 = `${parent2}.${path2}`;
if (oakFullpath2 !== this.data.oakFullpath) { if (oakFullpath2 !== this.data.oakFullpath) {
@ -559,7 +570,7 @@ function createComponentOptions(options, features, doSubscribe, exceptionRouterD
} }
} }
}, },
...makeComponentMethods(features, doSubscribe, formData, exceptionRouterDict) ...makeComponentMethods(features, doSubscribe, formData, exceptionRouterDict),
}, },
lifetimes: { lifetimes: {
async created() { async created() {
@ -598,7 +609,7 @@ function createComponentOptions(options, features, doSubscribe, exceptionRouterD
}, },
hide() { hide() {
this.unsubscribe(); this.unsubscribe();
} },
}, },
}; };
return componentOptions; return componentOptions;
@ -724,7 +735,7 @@ function initialize(storageSchema, createFeatures, createContext, exceptionRoute
}); });
}, },
OakComponent: (options, componentOptions = {}) => { OakComponent: (options, componentOptions = {}) => {
const oakOptions = createComponentOptions(options, features, subscribe, exceptionRouterDict); const oakOptions = createComponentOptions(options, subscribe, features, exceptionRouterDict);
const { properties, pageLifetimes, lifetimes, methods, data, observers } = oakOptions; const { properties, pageLifetimes, lifetimes, methods, data, observers } = oakOptions;
const { properties: p2, pageLifetimes: pl2, lifetimes: l2, methods: m2, data: d2, observers: o2, ...restOptions } = componentOptions; const { properties: p2, pageLifetimes: pl2, lifetimes: l2, methods: m2, data: d2, observers: o2, ...restOptions } = componentOptions;
const pls = [pageLifetimes, pl2].filter(ele => !!ele); const pls = [pageLifetimes, pl2].filter(ele => !!ele);

View File

@ -113,7 +113,7 @@ export class DebugStore<ED extends EntityDict, Cxt extends Context<ED>> extends
this.rwLock.acquire('X'); this.rwLock.acquire('X');
} }
endInitalizing() { endInitializing() {
this.rwLock.release(); this.rwLock.release();
} }
} }

View File

@ -26,11 +26,11 @@ async function initDataInStore<ED extends EntityDict, Cxt extends Context<ED>>(
} }
await context.commit(); await context.commit();
} }
store.endInitalizing(); store.endInitializing();
} }
function getMaterializedData() { function getMaterializedData() {
if (/* process.env.OAK_PLATFORM === 'weChatMp' */true) { if (process.env.OAK_PLATFORM === 'weChatMp') {
try { try {
const data = wx.getStorageSync('debugStore'); const data = wx.getStorageSync('debugStore');
const stat = wx.getStorageSync('debugStoreStat'); const stat = wx.getStorageSync('debugStoreStat');
@ -46,12 +46,31 @@ function getMaterializedData() {
return; return;
} }
} }
else if (process.env.OAK_PLATFORM === 'web') {
try {
const data = JSON.parse(
window.localStorage.getItem('debugStore') as string
);
const stat = JSON.parse(
window.localStorage.getItem('debugStoreStat') as string
);
if (data && stat) {
return {
data,
stat,
};
}
return;
} catch (e) {
return;
}
}
} }
let lastMaterializedVersion = 0; let lastMaterializedVersion = 0;
function materializeData(data: any, stat: { create: number, update: number, remove: number, commit: number }) { function materializeData(data: any, stat: { create: number, update: number, remove: number, commit: number }) {
if (/* process.env.OAK_PLATFORM === 'weChatMp' */true) { if (process.env.OAK_PLATFORM === 'weChatMp') {
try { try {
wx.setStorageSync('debugStore', data); wx.setStorageSync('debugStore', data);
wx.setStorageSync('debugStoreStat', stat); wx.setStorageSync('debugStoreStat', stat);
@ -69,6 +88,17 @@ function materializeData(data: any, stat: { create: number, update: number, remo
}); });
} }
} }
else if (process.env.OAK_PLATFORM === 'web') {
try {
window.localStorage.setItem('debugStore', typeof data === 'string' ? data : JSON.stringify(data));
window.localStorage.setItem('debugStoreStat', JSON.stringify(stat));
lastMaterializedVersion = stat.commit;
alert('数据已物化');
} catch (e) {
console.error(e);
alert('物化数据失败');
}
}
} }
/** /**

View File

@ -11,9 +11,4 @@ export * from './types/ExceptionRoute';
export { BasicFeatures } from './features'; export { BasicFeatures } from './features';
export * from './features/cache'; export * from './features/cache';
export * from './features/upload'; export * from './features/upload';
/* export {
initI18nWechatMp,
getI18nInstanceWechatMp,
I18nWechatMpRuntimeBase,
I18nWechatMp,
} from './platforms/wechatMp/i18n'; */

View File

@ -36,18 +36,18 @@ function createAspectProxy<ED extends EntityDict, Cxt extends Context<ED>,
return async (params: Parameters<typeof aspect>[0], scene: string) => { return async (params: Parameters<typeof aspect>[0], scene: string) => {
const runningContext = createContext(debugStore, scene); const runningContext = createContext(debugStore, scene);
await runningContext.begin(); await runningContext.begin();
let aspectCompeleted = false; let aspectCompleted = false;
try { try {
const result = await aspect(params, runningContext); const result = await aspect(params, runningContext);
await runningContext.commit(); await runningContext.commit();
aspectCompeleted = true; aspectCompleted = true;
await features.cache.sync(runningContext.opRecords); await features.cache.sync(runningContext.opRecords);
return result; return result;
} }
catch(err) { catch(err) {
if (!aspectCompeleted) { if (!aspectCompleted) {
await runningContext.rollback(); await runningContext.rollback();
} }
if (err instanceof OakRowInconsistencyException) { if (err instanceof OakRowInconsistencyException) {
// 在这里可以同步相应的数据 todo // 在这里可以同步相应的数据 todo

View File

@ -91,6 +91,12 @@ export class I18nWechatMpRuntimeBase implements CommonI18nInterface {
} }
} }
declare global {
const OakI18n: {
i18nInstance: I18nWechatMpRuntimeBase | null;
};
}
export function initI18nWechatMp(options: { export function initI18nWechatMp(options: {
locales: Locales; locales: Locales;
defaultLocale?: string; defaultLocale?: string;

View File

@ -9,7 +9,19 @@ import { assign, union } from "lodash";
import { ExceptionHandler, ExceptionRouters } from '../../types/ExceptionRoute'; import { ExceptionHandler, ExceptionRouters } from '../../types/ExceptionRoute';
import { NamedFilterItem, NamedSorterItem } from '../../types/NamedCondition'; import { NamedFilterItem, NamedSorterItem } from '../../types/NamedCondition';
import { CreateNodeOptions } from '../../features/runningTree'; import { CreateNodeOptions } from '../../features/runningTree';
import { getI18nInstanceWechatMp, CURRENT_LOCALE_KEY, CURRENT_LOCALE_DATA } from './i18n/index'; import {
initI18nWechatMp,
I18nWechatMpRuntimeBase,
getI18nInstanceWechatMp,
CURRENT_LOCALE_KEY,
CURRENT_LOCALE_DATA,
} from './i18n/index';
export {
initI18nWechatMp,
getI18nInstanceWechatMp,
I18nWechatMpRuntimeBase,
};
type RowSelected< type RowSelected<
ED extends EntityDict, ED extends EntityDict,
@ -750,15 +762,23 @@ function createPageOptions<ED extends EntityDict,
id: oakId, id: oakId,
}); });
// const oakFullpath = oakParent ? `${oakParent}.${oakPath || options.path}` : oakPath || options.path; // const oakFullpath = oakParent ? `${oakParent}.${oakPath || options.path}` : oakPath || options.path;
this.setData({ this.setData(
oakEntity: node.getEntity(), {
oakFullpath: path2, oakEntity: node.getEntity(),
oakFrom, oakFullpath: path2,
newOakActions: oakActions && JSON.parse(oakActions).length > 0 ? JSON.parse(oakActions) : options.actions || [], oakFrom,
}); newOakActions:
if (this.isReady) { oakActions && JSON.parse(oakActions).length > 0
this.refresh(); ? JSON.parse(oakActions)
} : options.actions || [],
},
() => {
this.isReady = true;
if (this.isReady) {
this.refresh();
}
}
);
}, },
...makeComponentMethods(features, doSubscribe, formData as any, exceptionRouterDict), ...makeComponentMethods(features, doSubscribe, formData as any, exceptionRouterDict),
@ -808,17 +828,20 @@ function createPageOptions<ED extends EntityDict,
} }
function createComponentOptions<ED extends EntityDict, function createComponentOptions<
ED extends EntityDict,
T extends keyof ED, T extends keyof ED,
Cxt extends Context<ED>, Cxt extends Context<ED>,
AD extends Record<string, Aspect<ED, Cxt>>, AD extends Record<string, Aspect<ED, Cxt>>,
FD extends Record<string, Feature<ED, Cxt, AD>>, FD extends Record<string, Feature<ED, Cxt, AD>>,
IsList extends boolean, IsList extends boolean,
FormedData extends WechatMiniprogram.Component.DataOption>( FormedData extends WechatMiniprogram.Component.DataOption
options: OakComponentOption<ED, T, Cxt, AD, FD, FormedData, IsList>, >(
features: BasicFeatures<ED, Cxt, AD> & FD, options: OakComponentOption<ED, T, Cxt, AD, FD, FormedData, IsList>,
doSubscribe: ReturnType<typeof init>['subscribe'], doSubscribe: ReturnType<typeof init>['subscribe'],
exceptionRouterDict: Record<string, ExceptionHandler>) { features: BasicFeatures<ED, Cxt, AD> & FD,
exceptionRouterDict: Record<string, ExceptionHandler>
) {
const { formData, entity } = options; const { formData, entity } = options;
const componentOptions: WechatMiniprogram.Component.Options< const componentOptions: WechatMiniprogram.Component.Options<
@ -833,21 +856,25 @@ function createComponentOptions<ED extends EntityDict,
oakParent: String, oakParent: String,
}, },
observers: { observers: {
"oakPath": function (path) { oakPath: function (path) {
return this.onPropsChanged({ return this.onPropsChanged({
path, path,
}) });
}, },
"oakParent": function (parent) { oakParent: function (parent) {
return this.onPropsChanged({ return this.onPropsChanged({
parent, parent,
}) });
} },
}, },
methods: { methods: {
async onPropsChanged(options) { async onPropsChanged(options) {
const path2 = options.hasOwnProperty('path') ? options.path! : this.data.oakPath; const path2 = options.hasOwnProperty('path')
const parent2 = options.hasOwnProperty('parent') ? options.parent! : this.data.oakParent; ? options.path!
: this.data.oakPath;
const parent2 = options.hasOwnProperty('parent')
? options.parent!
: this.data.oakParent;
if (path2 && parent2) { if (path2 && parent2) {
const oakFullpath2 = `${parent2}.${path2}`; const oakFullpath2 = `${parent2}.${path2}`;
if (oakFullpath2 !== this.data.oakFullpath) { if (oakFullpath2 !== this.data.oakFullpath) {
@ -859,7 +886,12 @@ function createComponentOptions<ED extends EntityDict,
} }
} }
}, },
...makeComponentMethods(features, doSubscribe, formData, exceptionRouterDict) ...makeComponentMethods(
features,
doSubscribe,
formData,
exceptionRouterDict
),
}, },
lifetimes: { lifetimes: {
@ -890,7 +922,6 @@ function createComponentOptions<ED extends EntityDict,
} }
}, },
async detached() { async detached() {
this.unsubscribe(); this.unsubscribe();
// await context.rollback(); // await context.rollback();
@ -904,7 +935,7 @@ function createComponentOptions<ED extends EntityDict,
}, },
hide() { hide() {
this.unsubscribe(); this.unsubscribe();
} },
}, },
}; };
@ -1088,7 +1119,7 @@ export function initialize<ED extends EntityDict, Cxt extends Context<ED>, AD ex
IS, IS,
true true
> = {}) => { > = {}) => {
const oakOptions = createComponentOptions(options, features, subscribe, exceptionRouterDict); const oakOptions = createComponentOptions(options, subscribe, features, exceptionRouterDict);
const { properties, pageLifetimes, lifetimes, methods, data, observers } = oakOptions; const { properties, pageLifetimes, lifetimes, methods, data, observers } = oakOptions;
const { properties: p2, pageLifetimes: pl2, lifetimes: l2, methods: m2, data: d2, observers: o2, ...restOptions } = componentOptions; const { properties: p2, pageLifetimes: pl2, lifetimes: l2, methods: m2, data: d2, observers: o2, ...restOptions } = componentOptions;

View File

@ -1,11 +1,5 @@
import { I18nWechatMpRuntimeBase } from '../platforms/wechatMp/i18n';
declare global { declare global {
const generateNewId: (options?: { timestamp?: boolean }) => Promise<string>; const generateNewId: (options?: { timestamp?: boolean }) => Promise<string>;
const OakI18n: {
i18nInstance: I18nWechatMpRuntimeBase | null;
} = {
i18nInstance: null,
};
} }
export {}; export {};

View File

@ -70,7 +70,9 @@
"node", "node",
"miniprogram-api-typings" "miniprogram-api-typings"
], ],
"include": [ "src/**/*.ts" ], "include": [
"src/**/*.ts",
],
"exclude": [ "exclude": [
"node_modules", "node_modules",
"**/*.spec.ts", "**/*.spec.ts",