diff --git a/lib/cacheStore/CacheStore.d.ts b/lib/cacheStore/CacheStore.d.ts index 192c95fa..d7f6d4bd 100644 --- a/lib/cacheStore/CacheStore.d.ts +++ b/lib/cacheStore/CacheStore.d.ts @@ -7,7 +7,7 @@ export declare class CacheStore, contextBuilder: (cxtString: string) => (store: CacheStore) => Cxt, getFullDataFn?: () => any, resetInitialDataFn?: () => void); + constructor(storageSchema: StorageSchema, contextBuilder: () => (store: CacheStore) => Cxt, getFullDataFn?: () => any, resetInitialDataFn?: () => void); operate(entity: T, operation: ED[T]['Operation'], context: Cxt, option: OP): Promise>; sync(opRecords: Array>, context: Cxt): Promise; select(entity: T, selection: S, context: Cxt, option: OP): Promise>; diff --git a/lib/cacheStore/CacheStore.js b/lib/cacheStore/CacheStore.js index 22801020..a1bba08c 100644 --- a/lib/cacheStore/CacheStore.js +++ b/lib/cacheStore/CacheStore.js @@ -8,8 +8,8 @@ var CacheStore = /** @class */ (function (_super) { tslib_1.__extends(CacheStore, _super); function CacheStore(storageSchema, contextBuilder, getFullDataFn, resetInitialDataFn) { var _this = _super.call(this, storageSchema) || this; - _this.executor = new TriggerExecutor_1.TriggerExecutor(function (cxtStr) { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) { - return [2 /*return*/, contextBuilder(cxtStr)(this)]; + _this.executor = new TriggerExecutor_1.TriggerExecutor(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) { + return [2 /*return*/, contextBuilder()(this)]; }); }); }); _this.getFullDataFn = getFullDataFn; _this.resetInitialDataFn = resetInitialDataFn; @@ -75,24 +75,26 @@ var CacheStore = /** @class */ (function (_super) { _a.sent(); _a.label = 2; case 2: - _a.trys.push([2, 4, , 6]); + _a.trys.push([2, 4, , 7]); return [4 /*yield*/, _super.prototype.sync.call(this, opRecords, context)]; case 3: result = _a.sent(); - return [3 /*break*/, 6]; + return [3 /*break*/, 7]; case 4: err_2 = _a.sent(); + if (!autoCommit) return [3 /*break*/, 6]; return [4 /*yield*/, context.rollback()]; case 5: _a.sent(); - throw err_2; - case 6: - if (!autoCommit) return [3 /*break*/, 8]; - return [4 /*yield*/, context.commit()]; + _a.label = 6; + case 6: throw err_2; case 7: + if (!autoCommit) return [3 /*break*/, 9]; + return [4 /*yield*/, context.commit()]; + case 8: _a.sent(); - _a.label = 8; - case 8: return [2 /*return*/, result]; + _a.label = 9; + case 9: return [2 /*return*/, result]; } }); }); diff --git a/lib/debugStore/DebugStore.d.ts b/lib/debugStore/DebugStore.d.ts new file mode 100644 index 00000000..f2a17462 --- /dev/null +++ b/lib/debugStore/DebugStore.d.ts @@ -0,0 +1,24 @@ +import { EntityDict, SelectOption, Context, RowStore, DeduceCreateOperation, DeduceRemoveOperation, DeduceUpdateOperation, OperateOption, SelectionResult, SelectRowShape } from "oak-domain/lib/types"; +import { TreeStore } from 'oak-memory-tree-store'; +import { StorageSchema, Trigger, Checker } from "oak-domain/lib/types"; +import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain'; +interface DebugStoreOperateOption extends OperateOption { + noLock?: true; +} +interface DebugStoreSelectOption extends SelectOption { + noLock?: true; +} +export declare class DebugStore> extends TreeStore { + private executor; + private rwLock; + constructor(storageSchema: StorageSchema, contextBuilder: (cxtString?: string) => (store: RowStore) => Promise); + protected cascadeUpdate(entity: T, operation: DeduceCreateOperation | DeduceUpdateOperation | DeduceRemoveOperation, context: Cxt, option: OP): Promise>; + protected cascadeSelect(entity: T, selection: S, context: Cxt, option: OP): Promise[]>; + operate(entity: T, operation: ED[T]['Operation'], context: Cxt, option: OP): Promise>; + select(entity: T, selection: S, context: Cxt, option: OP): Promise>; + registerTrigger(trigger: Trigger): void; + registerChecker(checker: Checker): void; + startInitializing(): void; + endInitializing(): void; +} +export {}; diff --git a/lib/debugStore/DebugStore.js b/lib/debugStore/DebugStore.js new file mode 100644 index 00000000..8a3bbcbd --- /dev/null +++ b/lib/debugStore/DebugStore.js @@ -0,0 +1,184 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.DebugStore = void 0; +var tslib_1 = require("tslib"); +var oak_memory_tree_store_1 = require("oak-memory-tree-store"); +var TriggerExecutor_1 = require("oak-domain/lib/store/TriggerExecutor"); +var concurrent_1 = require("oak-domain/lib/utils/concurrent"); +; +; +var DebugStore = /** @class */ (function (_super) { + tslib_1.__extends(DebugStore, _super); + function DebugStore(storageSchema, contextBuilder) { + var _this = _super.call(this, storageSchema) || this; + _this.executor = new TriggerExecutor_1.TriggerExecutor(function (cxtString) { return contextBuilder(cxtString)(_this); }); + _this.rwLock = new concurrent_1.RWLock(); + return _this; + } + DebugStore.prototype.cascadeUpdate = function (entity, operation, context, option) { + return tslib_1.__awaiter(this, void 0, void 0, function () { + var result; + return tslib_1.__generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!!option.blockTrigger) return [3 /*break*/, 2]; + return [4 /*yield*/, this.executor.preOperation(entity, operation, context, option)]; + case 1: + _a.sent(); + _a.label = 2; + case 2: + result = _super.prototype.cascadeUpdate.call(this, entity, operation, context, option); + if (!!option.blockTrigger) return [3 /*break*/, 4]; + return [4 /*yield*/, this.executor.postOperation(entity, operation, context, option)]; + case 3: + _a.sent(); + _a.label = 4; + case 4: return [2 /*return*/, result]; + } + }); + }); + }; + DebugStore.prototype.cascadeSelect = function (entity, selection, context, option) { + return tslib_1.__awaiter(this, void 0, void 0, function () { + var selection2, result; + return tslib_1.__generator(this, function (_a) { + switch (_a.label) { + case 0: + selection2 = Object.assign({ + action: 'select', + }, selection); + if (!!option.blockTrigger) return [3 /*break*/, 2]; + return [4 /*yield*/, this.executor.preOperation(entity, selection2, context, option)]; + case 1: + _a.sent(); + _a.label = 2; + case 2: return [4 /*yield*/, _super.prototype.cascadeSelect.call(this, entity, selection2, context, option)]; + case 3: + result = _a.sent(); + if (!!option.blockTrigger) return [3 /*break*/, 5]; + return [4 /*yield*/, this.executor.postOperation(entity, selection2, context, option, result)]; + case 4: + _a.sent(); + _a.label = 5; + case 5: return [2 /*return*/, result]; + } + }); + }); + }; + DebugStore.prototype.operate = function (entity, operation, context, option) { + return tslib_1.__awaiter(this, void 0, void 0, function () { + var autoCommit, result, err_1; + return tslib_1.__generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!!option.noLock) return [3 /*break*/, 2]; + return [4 /*yield*/, this.rwLock.acquire('S')]; + case 1: + _a.sent(); + _a.label = 2; + case 2: + autoCommit = !context.getCurrentTxnId(); + if (!autoCommit) return [3 /*break*/, 4]; + return [4 /*yield*/, context.begin()]; + case 3: + _a.sent(); + _a.label = 4; + case 4: + _a.trys.push([4, 6, , 9]); + return [4 /*yield*/, _super.prototype.operate.call(this, entity, operation, context, option)]; + case 5: + result = _a.sent(); + return [3 /*break*/, 9]; + case 6: + err_1 = _a.sent(); + if (!autoCommit) return [3 /*break*/, 8]; + return [4 /*yield*/, context.rollback()]; + case 7: + _a.sent(); + _a.label = 8; + case 8: + if (!option || !option.noLock) { + this.rwLock.release(); + } + throw err_1; + case 9: + if (!autoCommit) return [3 /*break*/, 11]; + return [4 /*yield*/, context.commit()]; + case 10: + _a.sent(); + _a.label = 11; + case 11: + if (!option || !option.noLock) { + this.rwLock.release(); + } + return [2 /*return*/, result]; + } + }); + }); + }; + DebugStore.prototype.select = function (entity, selection, context, option) { + return tslib_1.__awaiter(this, void 0, void 0, function () { + var autoCommit, result, err_2; + return tslib_1.__generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!(!option || !option.noLock)) return [3 /*break*/, 2]; + return [4 /*yield*/, this.rwLock.acquire('S')]; + case 1: + _a.sent(); + _a.label = 2; + case 2: + autoCommit = !context.getCurrentTxnId(); + if (!autoCommit) return [3 /*break*/, 4]; + return [4 /*yield*/, context.begin()]; + case 3: + _a.sent(); + _a.label = 4; + case 4: + _a.trys.push([4, 6, , 9]); + return [4 /*yield*/, _super.prototype.select.call(this, entity, selection, context, option)]; + case 5: + result = _a.sent(); + return [3 /*break*/, 9]; + case 6: + err_2 = _a.sent(); + if (!autoCommit) return [3 /*break*/, 8]; + return [4 /*yield*/, context.rollback()]; + case 7: + _a.sent(); + _a.label = 8; + case 8: + if (!option || !option.noLock) { + this.rwLock.release(); + } + throw err_2; + case 9: + if (!autoCommit) return [3 /*break*/, 11]; + return [4 /*yield*/, context.commit()]; + case 10: + _a.sent(); + _a.label = 11; + case 11: + if (!option || !option.noLock) { + this.rwLock.release(); + } + return [2 /*return*/, result]; + } + }); + }); + }; + DebugStore.prototype.registerTrigger = function (trigger) { + this.executor.registerTrigger(trigger); + }; + DebugStore.prototype.registerChecker = function (checker) { + this.executor.registerChecker(checker); + }; + DebugStore.prototype.startInitializing = function () { + this.rwLock.acquire('X'); + }; + DebugStore.prototype.endInitializing = function () { + this.rwLock.release(); + }; + return DebugStore; +}(oak_memory_tree_store_1.TreeStore)); +exports.DebugStore = DebugStore; diff --git a/lib/debugStore/index.d.ts b/lib/debugStore/index.d.ts index 14d8acd8..1ded5b45 100644 --- a/lib/debugStore/index.d.ts +++ b/lib/debugStore/index.d.ts @@ -1,7 +1,7 @@ -import { DebugStore } from './debugStore'; +import { DebugStore } from './DebugStore'; import { Checker, Trigger, StorageSchema, Context, EntityDict, RowStore, ActionDictOfEntityDict, Watcher } from "oak-domain/lib/types"; import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain'; export declare function clearMaterializedData(): void; -export declare function createDebugStore>(storageSchema: StorageSchema, contextBuilder: (cxtString?: string) => (store: RowStore) => Cxt, triggers: Array>, checkers: Array>, watchers: Array>, initialData?: { +export declare function createDebugStore>(storageSchema: StorageSchema, contextBuilder: (cxtString?: string) => (store: RowStore) => Promise, triggers: Array>, checkers: Array>, watchers: Array>, initialData?: { [T in keyof ED]?: Array; }, actionDict?: ActionDictOfEntityDict): DebugStore; diff --git a/lib/debugStore/index.js b/lib/debugStore/index.js index 9cf4ae00..d55fef37 100644 --- a/lib/debugStore/index.js +++ b/lib/debugStore/index.js @@ -2,7 +2,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.createDebugStore = exports.clearMaterializedData = void 0; var tslib_1 = require("tslib"); -var debugStore_1 = require("./debugStore"); +var DebugStore_1 = require("./DebugStore"); var actionDef_1 = require("oak-domain/lib/store/actionDef"); var assert_1 = require("oak-domain/lib/utils/assert"); function initDataInStore(store, initialData, stat) { @@ -135,79 +135,81 @@ function initializeWatchers(store, contextBuilder, watchers) { case 0: count++; start = Date.now(); - context = contextBuilder()(store); - _m.label = 1; + return [4 /*yield*/, contextBuilder()(store)]; case 1: - _m.trys.push([1, 27, 28, 29]); - watchers_1 = tslib_1.__values(watchers), watchers_1_1 = watchers_1.next(); + context = _m.sent(); _m.label = 2; case 2: - if (!!watchers_1_1.done) return [3 /*break*/, 26]; + _m.trys.push([2, 28, 29, 30]); + watchers_1 = tslib_1.__values(watchers), watchers_1_1 = watchers_1.next(); + _m.label = 3; + case 3: + if (!!watchers_1_1.done) return [3 /*break*/, 27]; w = watchers_1_1.value; return [4 /*yield*/, context.begin()]; - case 3: - _m.sent(); - _m.label = 4; case 4: - _m.trys.push([4, 23, , 25]); - if (!w.hasOwnProperty('actionData')) return [3 /*break*/, 13]; - _a = w, entity = _a.entity, action = _a.action, filter = _a.filter, actionData = _a.actionData; - if (!(typeof filter === 'function')) return [3 /*break*/, 6]; - return [4 /*yield*/, filter()]; + _m.sent(); + _m.label = 5; case 5: - _b = _m.sent(); - return [3 /*break*/, 7]; + _m.trys.push([5, 24, , 26]); + if (!w.hasOwnProperty('actionData')) return [3 /*break*/, 14]; + _a = w, entity = _a.entity, action = _a.action, filter = _a.filter, actionData = _a.actionData; + if (!(typeof filter === 'function')) return [3 /*break*/, 7]; + return [4 /*yield*/, filter()]; case 6: - _b = filter; - _m.label = 7; + _b = _m.sent(); + return [3 /*break*/, 8]; case 7: - filter2 = _b; - if (!(typeof actionData === 'function')) return [3 /*break*/, 9]; - return [4 /*yield*/, actionData()]; + _b = filter; + _m.label = 8; case 8: - _c = _m.sent(); - return [3 /*break*/, 10]; + filter2 = _b; + if (!(typeof actionData === 'function')) return [3 /*break*/, 10]; + return [4 /*yield*/, actionData()]; case 9: - _c = actionData; - _m.label = 10; + _c = _m.sent(); + return [3 /*break*/, 11]; case 10: + _c = actionData; + _m.label = 11; + case 11: data = _c; _e = (_d = store).operate; _f = [entity]; _l = {}; return [4 /*yield*/, generateNewId()]; - case 11: return [4 /*yield*/, _e.apply(_d, _f.concat([(_l.id = _m.sent(), + case 12: return [4 /*yield*/, _e.apply(_d, _f.concat([(_l.id = _m.sent(), _l.action = action, _l.data = data, _l.filter = filter2, _l), context, { dontCollect: true, }]))]; - case 12: + case 13: result = _m.sent(); console.log("\u6267\u884C\u4E86watcher\u3010".concat(w.name, "\u3011\uFF0C\u7ED3\u679C\u662F\uFF1A"), result); - return [3 /*break*/, 21]; - case 13: - _g = w, entity = _g.entity, projection = _g.projection, fn = _g.fn, filter = _g.filter; - if (!(typeof filter === 'function')) return [3 /*break*/, 15]; - return [4 /*yield*/, filter()]; + return [3 /*break*/, 22]; case 14: - _h = _m.sent(); - return [3 /*break*/, 16]; + _g = w, entity = _g.entity, projection = _g.projection, fn = _g.fn, filter = _g.filter; + if (!(typeof filter === 'function')) return [3 /*break*/, 16]; + return [4 /*yield*/, filter()]; case 15: - _h = filter; - _m.label = 16; + _h = _m.sent(); + return [3 /*break*/, 17]; case 16: - filter2 = _h; - if (!(typeof projection === 'function')) return [3 /*break*/, 18]; - return [4 /*yield*/, projection()]; + _h = filter; + _m.label = 17; case 17: - _j = _m.sent(); - return [3 /*break*/, 19]; + filter2 = _h; + if (!(typeof projection === 'function')) return [3 /*break*/, 19]; + return [4 /*yield*/, projection()]; case 18: - _j = projection; - _m.label = 19; + _j = _m.sent(); + return [3 /*break*/, 20]; case 19: + _j = projection; + _m.label = 20; + case 20: projection2 = _j; return [4 /*yield*/, store.select(entity, { data: projection2, @@ -215,37 +217,37 @@ function initializeWatchers(store, contextBuilder, watchers) { }, context, { dontCollect: true, })]; - case 20: + case 21: rows = (_m.sent()).result; result = fn(context, rows); console.log("\u6267\u884C\u4E86watcher\u3010".concat(w.name, "\u3011\uFF0C\u7ED3\u679C\u662F\uFF1A"), result); - _m.label = 21; - case 21: return [4 /*yield*/, context.commit()]; - case 22: - _m.sent(); - return [3 /*break*/, 25]; + _m.label = 22; + case 22: return [4 /*yield*/, context.commit()]; case 23: + _m.sent(); + return [3 /*break*/, 26]; + case 24: err_1 = _m.sent(); return [4 /*yield*/, context.rollback()]; - case 24: + case 25: _m.sent(); console.error("\u6267\u884C\u4E86watcher\u3010".concat(w.name, "\u3011\uFF0C\u53D1\u751F\u9519\u8BEF\uFF1A"), err_1); - return [3 /*break*/, 25]; - case 25: + return [3 /*break*/, 26]; + case 26: watchers_1_1 = watchers_1.next(); - return [3 /*break*/, 2]; - case 26: return [3 /*break*/, 29]; - case 27: + return [3 /*break*/, 3]; + case 27: return [3 /*break*/, 30]; + case 28: e_1_1 = _m.sent(); e_1 = { error: e_1_1 }; - return [3 /*break*/, 29]; - case 28: + return [3 /*break*/, 30]; + case 29: try { if (watchers_1_1 && !watchers_1_1.done && (_k = watchers_1.return)) _k.call(watchers_1); } finally { if (e_1) throw e_1.error; } return [7 /*endfinally*/]; - case 29: + case 30: duration = Date.now() - start; console.log("\u7B2C".concat(count, "\u6B21\u6267\u884Cwatchers\uFF0C\u5171\u6267\u884C").concat(watchers.length, "\u4E2A\uFF0C\u8017\u65F6").concat(duration, "\u6BEB\u79D2")); setTimeout(function () { return doWatchers(); }, 120000); @@ -271,7 +273,7 @@ function initializeWatchers(store, contextBuilder, watchers) { materializeData(data, store.getStat()); } */ function createDebugStore(storageSchema, contextBuilder, triggers, checkers, watchers, initialData, actionDict) { - var store = new debugStore_1.DebugStore(storageSchema, contextBuilder); + var store = new DebugStore_1.DebugStore(storageSchema, contextBuilder); triggers.forEach(function (ele) { return store.registerTrigger(ele); }); checkers.forEach(function (ele) { return store.registerChecker(ele); }); (0, assert_1.assert)(actionDict); diff --git a/lib/features/cache.d.ts b/lib/features/cache.d.ts index ca68cf9c..d565227d 100644 --- a/lib/features/cache.d.ts +++ b/lib/features/cache.d.ts @@ -1,15 +1,19 @@ -import { EntityDict, OperateOption, SelectOption, OpRecord, Context, AspectWrapper } from 'oak-domain/lib/types'; +import { EntityDict, OperateOption, SelectOption, OpRecord, Context, AspectWrapper, SelectionResult } from 'oak-domain/lib/types'; import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain'; import { CommonAspectDict } from 'oak-common-aspect'; import { Feature } from '../types/Feature'; import { CacheStore } from '../cacheStore/CacheStore'; export declare class Cache, AD extends CommonAspectDict> extends Feature { - cacheStore: CacheStore; - context: Cxt; + cacheStore?: CacheStore; private syncEventsCallbacks; - private contextBuilder; + private contextBuilder?; private syncLock; - constructor(aspectWrapper: AspectWrapper, context: Cxt, cacheStore: CacheStore, contextBuilder: () => Cxt); + constructor(aspectWrapper: AspectWrapper); + /** + * 目前context和cache会形成循环依赖,这里不太好处理,只能先让contextBuilder后注入 + * @param contextBuilder + */ + init(contextBuilder: () => Cxt, store: CacheStore): void; refresh(entity: T, selection: ED[T]['Selection'], option?: OP, getCount?: true): Promise<{ data: import("oak-domain/lib/types").SelectRowShape[]; count?: number | undefined; @@ -25,7 +29,7 @@ export declare class Cache(entity: T, operation: ED[T]['Operation']): Promise>; + testOperation(entity: T, operation: ED[T]['Operation']): Promise; /** * 尝试在cache中重做一些动作,然后选择重做后的数据(为了实现modi) * @param entity @@ -35,7 +39,7 @@ export declare class Cache(entity: T, selection: S, opers: Array<{ entity: keyof ED; operation: ED[keyof ED]['Operation']; - }>): Promise>; + }>): Promise>; get(entity: T, selection: S, params?: SelectOption): Promise[]>; judgeRelation(entity: keyof ED, attr: string): string | 0 | 1 | string[] | 2; bindOnSync(callback: (opRecords: OpRecord[]) => Promise): void; diff --git a/lib/features/cache.js b/lib/features/cache.js index bb8dad86..5955a454 100644 --- a/lib/features/cache.js +++ b/lib/features/cache.js @@ -9,12 +9,9 @@ var concurrent_1 = require("oak-domain/lib/utils/concurrent"); var Exception_1 = require("oak-domain/lib/types/Exception"); var Cache = /** @class */ (function (_super) { tslib_1.__extends(Cache, _super); - function Cache(aspectWrapper, context, cacheStore, contextBuilder) { + function Cache(aspectWrapper) { var _this = _super.call(this, aspectWrapper) || this; - _this.cacheStore = cacheStore; - _this.context = context; _this.syncEventsCallbacks = []; - _this.contextBuilder = contextBuilder; _this.syncLock = new concurrent_1.RWLock(); // 在这里把wrapper的返回opRecords截取到并同步到cache中 var exec = aspectWrapper.exec; @@ -37,6 +34,14 @@ var Cache = /** @class */ (function (_super) { }); }; return _this; } + /** + * 目前context和cache会形成循环依赖,这里不太好处理,只能先让contextBuilder后注入 + * @param contextBuilder + */ + Cache.prototype.init = function (contextBuilder, store) { + this.contextBuilder = contextBuilder; + this.cacheStore = store; + }; Cache.prototype.refresh = function (entity, selection, option, getCount) { return tslib_1.__awaiter(this, void 0, void 0, function () { var result; @@ -108,32 +113,34 @@ var Cache = /** @class */ (function (_super) { */ Cache.prototype.testOperation = function (entity, operation) { return tslib_1.__awaiter(this, void 0, void 0, function () { - var result, err_1; + var context, err_1; return tslib_1.__generator(this, function (_a) { switch (_a.label) { - case 0: return [4 /*yield*/, this.context.begin()]; + case 0: + context = this.contextBuilder(); + return [4 /*yield*/, context.begin()]; case 1: _a.sent(); _a.label = 2; case 2: _a.trys.push([2, 5, , 7]); - return [4 /*yield*/, this.cacheStore.operate(entity, operation, this.context, { + return [4 /*yield*/, this.cacheStore.operate(entity, operation, context, { dontCollect: true, dontCreateOper: true, })]; case 3: - result = _a.sent(); - return [4 /*yield*/, this.context.rollback()]; + _a.sent(); + return [4 /*yield*/, context.rollback()]; case 4: _a.sent(); return [3 /*break*/, 7]; case 5: err_1 = _a.sent(); - return [4 /*yield*/, this.context.rollback()]; + return [4 /*yield*/, context.rollback()]; case 6: _a.sent(); throw err_1; - case 7: return [2 /*return*/, result]; + case 7: return [2 /*return*/, true]; } }); }); @@ -146,11 +153,13 @@ var Cache = /** @class */ (function (_super) { */ Cache.prototype.tryRedoOperations = function (entity, selection, opers) { return tslib_1.__awaiter(this, void 0, void 0, function () { - var result, opers_1, opers_1_1, oper, e_1_1, err_2, missedRows; + var result, context, opers_1, opers_1_1, oper, e_1_1, err_2, missedRows; var e_1, _a; return tslib_1.__generator(this, function (_b) { switch (_b.label) { - case 0: return [4 /*yield*/, this.context.begin()]; + case 0: + context = this.contextBuilder(); + return [4 /*yield*/, context.begin()]; case 1: _b.sent(); _b.label = 2; @@ -161,7 +170,7 @@ var Cache = /** @class */ (function (_super) { case 3: if (!!opers_1_1.done) return [3 /*break*/, 6]; oper = opers_1_1.value; - return [4 /*yield*/, this.cacheStore.operate(oper.entity, oper.operation, this.context, { + return [4 /*yield*/, this.cacheStore.operate(oper.entity, oper.operation, context, { dontCollect: true, dontCreateOper: true, blockTrigger: true, @@ -188,12 +197,12 @@ var Cache = /** @class */ (function (_super) { _b.label = 10; case 10: _b.trys.push([10, 13, , 18]); - return [4 /*yield*/, this.cacheStore.select(entity, selection, this.context, { + return [4 /*yield*/, this.cacheStore.select(entity, selection, context, { dontCollect: true, })]; case 11: result = _b.sent(); - return [4 /*yield*/, this.context.rollback()]; + return [4 /*yield*/, context.rollback()]; case 12: _b.sent(); return [2 /*return*/, result]; @@ -205,7 +214,7 @@ var Cache = /** @class */ (function (_super) { case 14: _b.sent(); return [3 /*break*/, 17]; - case 15: return [4 /*yield*/, this.context.rollback()]; + case 15: return [4 /*yield*/, context.rollback()]; case 16: _b.sent(); throw err_2; @@ -218,10 +227,12 @@ var Cache = /** @class */ (function (_super) { }; Cache.prototype.get = function (entity, selection, params) { return tslib_1.__awaiter(this, void 0, void 0, function () { - var result; + var context, result; return tslib_1.__generator(this, function (_a) { switch (_a.label) { - case 0: return [4 /*yield*/, this.cacheStore.select(entity, selection, this.context, {})]; + case 0: + context = this.contextBuilder(); + return [4 /*yield*/, this.cacheStore.select(entity, selection, context, {})]; case 1: result = (_a.sent()).result; return [2 /*return*/, result]; diff --git a/lib/features/index.d.ts b/lib/features/index.d.ts index f3524dae..2276b213 100644 --- a/lib/features/index.d.ts +++ b/lib/features/index.d.ts @@ -10,8 +10,16 @@ import { EventBus } from './eventBus'; import { LocalStorage } from './localStorage'; import { Notification } from './notification'; import { Message } from './message'; -import { CacheStore } from '../cacheStore/CacheStore'; -export declare function initialize, AD extends CommonAspectDict>(aspectWrapper: AspectWrapper, storageSchema: StorageSchema, context: Cxt, cacheStore: CacheStore, contextBuilder: () => Cxt): BasicFeatures; +export declare function initialize, AD extends CommonAspectDict>(aspectWrapper: AspectWrapper, storageSchema: StorageSchema): { + cache: Cache; + location: Location; + runningTree: RunningTree; + locales: Locales; + eventBus: EventBus; + localStorage: LocalStorage; + notification: Notification; + message: Message; +}; export declare type BasicFeatures, AD extends CommonAspectDict> = { cache: Cache; location: Location; diff --git a/lib/features/index.js b/lib/features/index.js index d09db557..b0e717dc 100644 --- a/lib/features/index.js +++ b/lib/features/index.js @@ -9,8 +9,8 @@ var eventBus_1 = require("./eventBus"); var localStorage_1 = require("./localStorage"); var notification_1 = require("./notification"); var message_1 = require("./message"); -function initialize(aspectWrapper, storageSchema, context, cacheStore, contextBuilder) { - var cache = new cache_1.Cache(aspectWrapper, context, cacheStore, contextBuilder); +function initialize(aspectWrapper, storageSchema) { + var cache = new cache_1.Cache(aspectWrapper); var location = new location_1.Location(aspectWrapper); var runningTree = new runningTree_1.RunningTree(aspectWrapper, cache, storageSchema); var locales = new locales_1.Locales(aspectWrapper); diff --git a/lib/initialize-dev.d.ts b/lib/initialize-dev.d.ts index 18b03df3..d67ccde6 100644 --- a/lib/initialize-dev.d.ts +++ b/lib/initialize-dev.d.ts @@ -6,7 +6,6 @@ import { BasicFeatures } from './features'; import { ActionDictOfEntityDict } from 'oak-domain/lib/types/Action'; import { CommonAspectDict } from 'oak-common-aspect'; /** - * dev模式下,前后端可以使用同一个Cxt,内部自己区分 * @param storageSchema * @param createFeatures * @param contextBuilder @@ -19,15 +18,65 @@ import { CommonAspectDict } from 'oak-common-aspect'; * @param actionDict * @returns */ -export declare function initialize, AD extends Record>, FD extends Record>>>(storageSchema: StorageSchema, createFeatures: (aspectWrapper: AspectWrapper, basicFeatures: BasicFeatures>, context: Cxt) => FD, contextBuilder: (cxtString?: string) => (store: RowStore) => Cxt, aspectDict: AD, triggers?: Array>, checkers?: Array>, watchers?: Array>, initialData?: { +export declare function initialize, AD extends Record>, FD extends Record>>>(storageSchema: StorageSchema, createFeatures: (aspectWrapper: AspectWrapper, basicFeatures: BasicFeatures>) => FD, frontendContextBuilder: (features: FD & BasicFeatures>) => (store: RowStore) => Cxt, backendContextBuilder: (contextStr?: string) => (store: RowStore) => Promise, aspectDict: AD, triggers?: Array>, checkers?: Array>, watchers?: Array>, initialData?: { [T in keyof ED]?: Array; }, actionDict?: ActionDictOfEntityDict): { - features: BasicFeatures & FD; - context: Cxt; + features: { + cache: import(".").Cache; + location: import("./features/location").Location; + runningTree: import("./features/runningTree").RunningTree; + locales: import("./features/locales").Locales; + eventBus: import("./features/eventBus").EventBus; + localStorage: import(".").LocalStorage; + notification: import("./features/notification").Notification; + message: import("./features/message").Message; + } & FD; }; diff --git a/lib/initialize-dev.js b/lib/initialize-dev.js index a0a2f1ae..bb984c33 100644 --- a/lib/initialize-dev.js +++ b/lib/initialize-dev.js @@ -11,7 +11,6 @@ var oak_common_aspect_1 = tslib_1.__importDefault(require("oak-common-aspect")); var actionDef_1 = require("oak-domain/lib/store/actionDef"); var CacheStore_1 = require("./cacheStore/CacheStore"); /** - * dev模式下,前后端可以使用同一个Cxt,内部自己区分 * @param storageSchema * @param createFeatures * @param contextBuilder @@ -24,70 +23,73 @@ var CacheStore_1 = require("./cacheStore/CacheStore"); * @param actionDict * @returns */ -function initialize(storageSchema, createFeatures, contextBuilder, aspectDict, triggers, checkers, watchers, initialData, actionDict) { +function initialize(storageSchema, createFeatures, frontendContextBuilder, backendContextBuilder, aspectDict, triggers, checkers, watchers, initialData, actionDict) { var _this = this; - var intersect = (0, lodash_1.intersection)(Object.keys(oak_common_aspect_1.default), Object.keys(aspectDict)); - if (intersect.length > 0) { - throw new Error("\u7528\u6237\u5B9A\u4E49\u7684aspect\u4E2D\u4E0D\u80FD\u548C\u7CFB\u7EDFaspect\u540C\u540D\uFF1A\u300C".concat(intersect.join(','), "\u300D")); + var intersected = (0, lodash_1.intersection)(Object.keys(oak_common_aspect_1.default), Object.keys(aspectDict)); + if (intersected.length > 0) { + throw new Error("\u7528\u6237\u5B9A\u4E49\u7684aspect\u4E2D\u4E0D\u80FD\u548C\u7CFB\u7EDFaspect\u540C\u540D\uFF1A\u300C".concat(intersected.join(','), "\u300D")); } var aspectDict2 = Object.assign({}, oak_common_aspect_1.default, aspectDict); var checkers2 = (0, index_1.createDynamicCheckers)(storageSchema).concat(checkers || []); var triggers2 = (0, index_2.createDynamicTriggers)(storageSchema).concat(triggers || []); - var debugStore = (0, debugStore_1.createDebugStore)(storageSchema, contextBuilder, triggers2, checkers2, watchers || [], initialData, actionDict); - var cacheStore = new CacheStore_1.CacheStore(storageSchema, contextBuilder, function () { return debugStore.getCurrentData(); }, function () { return (0, debugStore_1.clearMaterializedData)(); }); + var debugStore = (0, debugStore_1.createDebugStore)(storageSchema, backendContextBuilder, triggers2, checkers2, watchers || [], initialData, actionDict); + var wrapper = {}; + var basicFeatures = (0, features_1.initialize)(wrapper, storageSchema); + var userDefinedfeatures = createFeatures(wrapper, basicFeatures); + intersected = (0, lodash_1.intersection)(Object.keys(basicFeatures), Object.keys(userDefinedfeatures)); + if (intersected.length > 0) { + throw new Error("\u7528\u6237\u5B9A\u4E49\u7684feature\u4E2D\u4E0D\u80FD\u548C\u7CFB\u7EDFfeature\u540C\u540D\uFF1A\u300C".concat(intersected.join(','), "\u300D")); + } + var features = Object.assign(basicFeatures, userDefinedfeatures); + // feature 和 wrapper在这里又形成了相互调用 + wrapper.exec = function (name, params) { return tslib_1.__awaiter(_this, void 0, void 0, function () { + var context, str, contextBackend, result, err_1; + return tslib_1.__generator(this, function (_a) { + switch (_a.label) { + case 0: + context = frontendContextBuilder(features)(cacheStore); + return [4 /*yield*/, context.toString()]; + case 1: + str = _a.sent(); + return [4 /*yield*/, backendContextBuilder(str)(debugStore)]; + case 2: + contextBackend = _a.sent(); + return [4 /*yield*/, contextBackend.begin()]; + case 3: + _a.sent(); + _a.label = 4; + case 4: + _a.trys.push([4, 7, , 9]); + return [4 /*yield*/, aspectDict2[name](params, contextBackend)]; + case 5: + result = _a.sent(); + return [4 /*yield*/, contextBackend.commit()]; + case 6: + _a.sent(); + return [3 /*break*/, 9]; + case 7: + err_1 = _a.sent(); + return [4 /*yield*/, contextBackend.rollback()]; + case 8: + _a.sent(); + throw err_1; + case 9: return [2 /*return*/, { + result: result, + opRecords: contextBackend.opRecords, + }]; + } + }); + }); }; + var cacheStore = new CacheStore_1.CacheStore(storageSchema, function () { return frontendContextBuilder(features); }, function () { return debugStore.getCurrentData(); }, function () { return (0, debugStore_1.clearMaterializedData)(); }); + // cache这个feature依赖于cacheStore和contextBuilder,后注入 + basicFeatures.cache.init(function () { return frontendContextBuilder(features)(cacheStore); }, cacheStore); checkers2.forEach(function (checker) { return cacheStore.registerChecker(checker); }); if (actionDict) { var adCheckers = (0, actionDef_1.analyzeActionDefDict)(storageSchema, actionDict).checkers; adCheckers.forEach(function (checker) { return cacheStore.registerChecker(checker); }); } - var context = contextBuilder()(cacheStore); - var wrapper = { - exec: function (name, params) { return tslib_1.__awaiter(_this, void 0, void 0, function () { - var str, contextBackend, result, err_1; - return tslib_1.__generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, context.toString()]; - case 1: - str = _a.sent(); - contextBackend = contextBuilder(str)(debugStore); - return [4 /*yield*/, contextBackend.begin()]; - case 2: - _a.sent(); - _a.label = 3; - case 3: - _a.trys.push([3, 6, , 8]); - return [4 /*yield*/, aspectDict2[name](params, contextBackend)]; - case 4: - result = _a.sent(); - return [4 /*yield*/, contextBackend.commit()]; - case 5: - _a.sent(); - return [3 /*break*/, 8]; - case 6: - err_1 = _a.sent(); - return [4 /*yield*/, contextBackend.rollback()]; - case 7: - _a.sent(); - throw err_1; - case 8: return [2 /*return*/, { - result: result, - opRecords: contextBackend.opRecords, - }]; - } - }); - }); }, - }; - var basicFeatures = (0, features_1.initialize)(wrapper, storageSchema, context, cacheStore, function () { return contextBuilder()(cacheStore); }); - // basicFeatures.runningNode.setStorageSchema(storageSchema); - var userDefinedFeatures = createFeatures(wrapper, basicFeatures, context); - intersect = (0, lodash_1.intersection)(Object.keys(basicFeatures), Object.keys(userDefinedFeatures)); - if (intersect.length > 0) { - throw new Error("\u7528\u6237\u5B9A\u4E49\u7684feature\u4E2D\u4E0D\u80FD\u548C\u7CFB\u7EDFfeature\u540C\u540D\uFF1A\u300C".concat(intersect.join(','), "\u300D")); - } - var features = Object.assign(basicFeatures, userDefinedFeatures); return { features: features, - context: context, }; } exports.initialize = initialize; diff --git a/lib/initialize-prod.d.ts b/lib/initialize-prod.d.ts index 4f500021..f742be56 100644 --- a/lib/initialize-prod.d.ts +++ b/lib/initialize-prod.d.ts @@ -18,7 +18,15 @@ import { CommonAspectDict } from 'oak-common-aspect'; * @param actionDict * @returns */ -export declare function initialize, AD extends Record>, FD extends Record>>>(storageSchema: StorageSchema, createFeatures: (aspectWrapper: AspectWrapper, basicFeatures: BasicFeatures>, context: Cxt) => FD, contextBuilder: (cxtString?: string) => (store: RowStore) => Cxt, connector: Connector, checkers?: Array>, actionDict?: ActionDictOfEntityDict): { - features: BasicFeatures> & FD; - context: Cxt; +export declare function initialize, AD extends Record>, FD extends Record>>>(storageSchema: StorageSchema, createFeatures: (aspectWrapper: AspectWrapper, basicFeatures: BasicFeatures>) => FD, frontendContextBuilder: (features: FD & BasicFeatures>) => (store: RowStore) => Cxt, connector: Connector, checkers?: Array>, actionDict?: ActionDictOfEntityDict): { + features: { + cache: import(".").Cache>; + location: import("./features/location").Location>; + runningTree: import("./features/runningTree").RunningTree>; + locales: import("./features/locales").Locales>; + eventBus: import("./features/eventBus").EventBus>; + localStorage: import(".").LocalStorage>; + notification: import("./features/notification").Notification>; + message: import("./features/message").Message>; + } & FD; }; diff --git a/lib/initialize-prod.js b/lib/initialize-prod.js index c05770e8..6aa1e5f2 100644 --- a/lib/initialize-prod.js +++ b/lib/initialize-prod.js @@ -26,43 +26,43 @@ function makeContentTypeAndBody(data) { * @param actionDict * @returns */ -function initialize(storageSchema, createFeatures, contextBuilder, connector, checkers, actionDict) { +function initialize(storageSchema, createFeatures, frontendContextBuilder, connector, checkers, actionDict) { var _this = this; - var cacheStore = new CacheStore_1.CacheStore(storageSchema, contextBuilder); var checkers2 = (0, checkers_1.createDynamicCheckers)(storageSchema).concat(checkers || []); + var wrapper = {}; + var basicFeatures = (0, features_1.initialize)(wrapper, storageSchema); + var userDefinedfeatures = createFeatures(wrapper, basicFeatures); + var intersected = (0, lodash_1.intersection)(Object.keys(basicFeatures), Object.keys(userDefinedfeatures)); + if (intersected.length > 0) { + throw new Error("\u7528\u6237\u5B9A\u4E49\u7684feature\u4E2D\u4E0D\u80FD\u548C\u7CFB\u7EDFfeature\u540C\u540D\uFF1A\u300C".concat(intersected.join(','), "\u300D")); + } + var features = Object.assign(basicFeatures, userDefinedfeatures); + var cacheStore = new CacheStore_1.CacheStore(storageSchema, function () { return frontendContextBuilder(features); }); + wrapper.exec = function (name, params) { return tslib_1.__awaiter(_this, void 0, void 0, function () { + var context, _a, result, opRecords; + return tslib_1.__generator(this, function (_b) { + switch (_b.label) { + case 0: + context = frontendContextBuilder(features)(cacheStore); + return [4 /*yield*/, connector.callAspect(name, params, context)]; + case 1: + _a = _b.sent(), result = _a.result, opRecords = _a.opRecords; + return [2 /*return*/, { + result: result, + opRecords: opRecords, + }]; + } + }); + }); }, + // cache这个feature依赖于cacheStore和contextBuilder,后注入 + basicFeatures.cache.init(function () { return frontendContextBuilder(features)(cacheStore); }, cacheStore); checkers2.forEach(function (checker) { return cacheStore.registerChecker(checker); }); if (actionDict) { var adCheckers = (0, actionDef_1.analyzeActionDefDict)(storageSchema, actionDict).checkers; adCheckers.forEach(function (checker) { return cacheStore.registerChecker(checker); }); } - var context = contextBuilder()(cacheStore); - var wrapper = { - exec: function (name, params) { return tslib_1.__awaiter(_this, void 0, void 0, function () { - var _a, result, opRecords; - return tslib_1.__generator(this, function (_b) { - switch (_b.label) { - case 0: return [4 /*yield*/, connector.callAspect(name, params, context)]; - case 1: - _a = _b.sent(), result = _a.result, opRecords = _a.opRecords; - return [2 /*return*/, { - result: result, - opRecords: opRecords, - }]; - } - }); - }); }, - }; - var basicFeatures = (0, features_1.initialize)(wrapper, storageSchema, context, cacheStore, function () { return contextBuilder()(cacheStore); }); - // basicFeatures.runningNode.setStorageSchema(storageSchema); - var userDefinedfeatures = createFeatures(wrapper, basicFeatures, context); - var intersect = (0, lodash_1.intersection)(Object.keys(basicFeatures), Object.keys(userDefinedfeatures)); - if (intersect.length > 0) { - throw new Error("\u7528\u6237\u5B9A\u4E49\u7684feature\u4E2D\u4E0D\u80FD\u548C\u7CFB\u7EDFfeature\u540C\u540D\uFF1A\u300C".concat(intersect.join(','), "\u300D")); - } - var features = Object.assign(basicFeatures, userDefinedfeatures); return { features: features, - context: context, }; } exports.initialize = initialize; diff --git a/lib/initialize.dev.mp.d.ts b/lib/initialize.dev.mp.d.ts index fcb1994e..873992dd 100644 --- a/lib/initialize.dev.mp.d.ts +++ b/lib/initialize.dev.mp.d.ts @@ -8,8 +8,66 @@ import { ActionDictOfEntityDict } from 'oak-domain/lib/types/Action'; import { CommonAspectDict } from 'oak-common-aspect'; import { ExceptionRouters } from './types/ExceptionRoute'; import { I18nOptions } from './platforms/wechatMp/i18n'; -export declare function initialize, AD extends Record>, FD extends Record>>>(storageSchema: StorageSchema, createFeatures: (aspectWrapper: AspectWrapper, basicFeatures: BasicFeatures>, context: Cxt) => FD, contextBuilder: (cxtString?: string) => (store: RowStore) => Cxt, aspectDict: AD, exceptionRouters?: ExceptionRouters, triggers?: Array>, checkers?: Array>, watchers?: Array>, initialData?: { +export declare function initialize, AD extends Record>, FD extends Record>>>(storageSchema: StorageSchema, createFeatures: (aspectWrapper: AspectWrapper, basicFeatures: BasicFeatures>) => FD, frontendContextBuilder: (features: FD & BasicFeatures>) => (store: RowStore) => Cxt, backendContextBuilder: (contextStr?: string) => (store: RowStore) => Promise, aspectDict: AD, exceptionRouters?: ExceptionRouters, triggers?: Array>, checkers?: Array>, watchers?: Array>, initialData?: { [T in keyof ED]?: Array; }, actionDict?: ActionDictOfEntityDict, i18nOptions?: I18nOptions): { i18n: import("./platforms/wechatMp/i18n").I18nWechatMpRuntimeBase; + features: { + cache: import(".").Cache; + location: import("./features/location").Location; + runningTree: import("./features/runningTree").RunningTree; + locales: import("./features/locales").Locales; + eventBus: import("./features/eventBus").EventBus; + localStorage: import(".").LocalStorage; + notification: import("./features/notification").Notification; + message: import("./features/message").Message; + } & FD; }; diff --git a/lib/initialize.dev.mp.js b/lib/initialize.dev.mp.js index 66c6384f..c5d3aae6 100644 --- a/lib/initialize.dev.mp.js +++ b/lib/initialize.dev.mp.js @@ -6,10 +6,10 @@ require("./utils/wx.polyfill"); var page_mp_1 = require("./page.mp"); var initialize_dev_1 = require("./initialize-dev"); var i18n_1 = require("./platforms/wechatMp/i18n"); -function initialize(storageSchema, createFeatures, contextBuilder, aspectDict, exceptionRouters, triggers, checkers, watchers, initialData, actionDict, i18nOptions) { +function initialize(storageSchema, createFeatures, frontendContextBuilder, backendContextBuilder, aspectDict, exceptionRouters, triggers, checkers, watchers, initialData, actionDict, i18nOptions) { var e_1, _a, _b; if (exceptionRouters === void 0) { exceptionRouters = []; } - var _c = (0, initialize_dev_1.initialize)(storageSchema, createFeatures, contextBuilder, aspectDict, triggers, checkers, watchers, initialData, actionDict), features = _c.features, context = _c.context; + var features = (0, initialize_dev_1.initialize)(storageSchema, createFeatures, frontendContextBuilder, backendContextBuilder, aspectDict, triggers, checkers, watchers, initialData, actionDict).features; var exceptionRouterDict = {}; try { for (var exceptionRouters_1 = tslib_1.__values(exceptionRouters), exceptionRouters_1_1 = exceptionRouters_1.next(); !exceptionRouters_1_1.done; exceptionRouters_1_1 = exceptionRouters_1.next()) { @@ -30,14 +30,15 @@ function initialize(storageSchema, createFeatures, contextBuilder, aspectDict, e var i18n = (0, i18n_1.getI18next)(i18nOptions); Object.assign(global, { OakPage: function (options) { - return (0, page_mp_1.createPage)(options, features, exceptionRouterDict, context); + return (0, page_mp_1.createPage)(options, features, exceptionRouterDict); }, OakComponent: function (options) { - return (0, page_mp_1.createComponent)(options, features, exceptionRouterDict, context); + return (0, page_mp_1.createComponent)(options, features, exceptionRouterDict); }, }); return { i18n: i18n, + features: features, }; } exports.initialize = initialize; diff --git a/lib/initialize.dev.web.d.ts b/lib/initialize.dev.web.d.ts index 14baef1e..abefbfed 100644 --- a/lib/initialize.dev.web.d.ts +++ b/lib/initialize.dev.web.d.ts @@ -8,8 +8,66 @@ import { ActionDictOfEntityDict } from 'oak-domain/lib/types/Action'; import { CommonAspectDict } from 'oak-common-aspect'; import { ExceptionRouters } from './types/ExceptionRoute'; import { I18nOptions } from './platforms/web/i18n'; -export declare function initialize, AD extends Record>, FD extends Record>>>(storageSchema: StorageSchema, createFeatures: (aspectWrapper: AspectWrapper, basicFeatures: BasicFeatures>, context: Cxt) => FD, contextBuilder: (cxtString?: string) => (store: RowStore) => Cxt, aspectDict: AD, exceptionRouters?: ExceptionRouters, triggers?: Array>, checkers?: Array>, watchers?: Array>, initialData?: { +export declare function initialize, AD extends Record>, FD extends Record>>>(storageSchema: StorageSchema, createFeatures: (aspectWrapper: AspectWrapper, basicFeatures: BasicFeatures>) => FD, frontendContextBuilder: (features: FD & BasicFeatures>) => (store: RowStore) => Cxt, backendContextBuilder: (contextStr?: string) => (store: RowStore) => Promise, aspectDict: AD, exceptionRouters?: ExceptionRouters, triggers?: Array>, checkers?: Array>, watchers?: Array>, initialData?: { [T in keyof ED]?: Array; }, actionDict?: ActionDictOfEntityDict, i18nOptions?: I18nOptions): { i18n: import("i18next").i18n; + features: { + cache: import(".").Cache; + location: import("./features/location").Location; + runningTree: import("./features/runningTree").RunningTree; + locales: import("./features/locales").Locales; + eventBus: import("./features/eventBus").EventBus; + localStorage: import(".").LocalStorage; + notification: import("./features/notification").Notification; + message: import("./features/message").Message; + } & FD; }; diff --git a/lib/initialize.dev.web.js b/lib/initialize.dev.web.js index 50b2574e..59cf4a48 100644 --- a/lib/initialize.dev.web.js +++ b/lib/initialize.dev.web.js @@ -6,10 +6,10 @@ require("./utils/wx.polyfill"); var page_web_1 = require("./page.web"); var initialize_dev_1 = require("./initialize-dev"); var i18n_1 = require("./platforms/web/i18n"); -function initialize(storageSchema, createFeatures, contextBuilder, aspectDict, exceptionRouters, triggers, checkers, watchers, initialData, actionDict, i18nOptions) { +function initialize(storageSchema, createFeatures, frontendContextBuilder, backendContextBuilder, aspectDict, exceptionRouters, triggers, checkers, watchers, initialData, actionDict, i18nOptions) { var e_1, _a, _b; if (exceptionRouters === void 0) { exceptionRouters = []; } - var _c = (0, initialize_dev_1.initialize)(storageSchema, createFeatures, contextBuilder, aspectDict, triggers, checkers, watchers, initialData, actionDict), features = _c.features, context = _c.context; + var features = (0, initialize_dev_1.initialize)(storageSchema, createFeatures, frontendContextBuilder, backendContextBuilder, aspectDict, triggers, checkers, watchers, initialData, actionDict).features; var exceptionRouterDict = {}; try { for (var exceptionRouters_1 = tslib_1.__values(exceptionRouters), exceptionRouters_1_1 = exceptionRouters_1.next(); !exceptionRouters_1_1.done; exceptionRouters_1_1 = exceptionRouters_1.next()) { @@ -30,14 +30,15 @@ function initialize(storageSchema, createFeatures, contextBuilder, aspectDict, e var i18n = (0, i18n_1.getI18next)(i18nOptions); Object.assign(global, { OakPage: function (options) { - return (0, page_web_1.createPage)(options, features, exceptionRouterDict, context); + return (0, page_web_1.createPage)(options, features, exceptionRouterDict); }, OakComponent: function (options) { - return (0, page_web_1.createComponent)(options, features, exceptionRouterDict, context); + return (0, page_web_1.createComponent)(options, features, exceptionRouterDict); }, }); return { i18n: i18n, + features: features, }; } exports.initialize = initialize; diff --git a/lib/initialize.prod.mp.d.ts b/lib/initialize.prod.mp.d.ts index cde77d78..950fb0b9 100644 --- a/lib/initialize.prod.mp.d.ts +++ b/lib/initialize.prod.mp.d.ts @@ -8,6 +8,16 @@ import { ActionDictOfEntityDict } from 'oak-domain/lib/types/Action'; import { CommonAspectDict } from 'oak-common-aspect'; import { ExceptionRouters } from './types/ExceptionRoute'; import { I18nOptions } from './platforms/wechatMp/i18n'; -export declare function initialize, AD extends Record>, FD extends Record>>>(storageSchema: StorageSchema, createFeatures: (aspectWrapper: AspectWrapper, basicFeatures: BasicFeatures>, context: Cxt) => FD, contextBuilder: (cxtString?: string) => (store: RowStore) => Cxt, exceptionRouters: ExceptionRouters | undefined, connector: Connector, checkers?: Array>, actionDict?: ActionDictOfEntityDict, i18nOptions?: I18nOptions): { +export declare function initialize, AD extends Record>, FD extends Record>>>(storageSchema: StorageSchema, createFeatures: (aspectWrapper: AspectWrapper, basicFeatures: BasicFeatures>) => FD, frontendContextBuilder: (features: FD & BasicFeatures>) => (store: RowStore) => Cxt, exceptionRouters: ExceptionRouters | undefined, connector: Connector, checkers?: Array>, actionDict?: ActionDictOfEntityDict, i18nOptions?: I18nOptions): { i18n: import("./platforms/wechatMp/i18n").I18nWechatMpRuntimeBase; + features: { + cache: import(".").Cache>; + location: import("./features/location").Location>; + runningTree: import("./features/runningTree").RunningTree>; + locales: import("./features/locales").Locales>; + eventBus: import("./features/eventBus").EventBus>; + localStorage: import(".").LocalStorage>; + notification: import("./features/notification").Notification>; + message: import("./features/message").Message>; + } & FD; }; diff --git a/lib/initialize.prod.mp.js b/lib/initialize.prod.mp.js index b476ad21..f8aca614 100644 --- a/lib/initialize.prod.mp.js +++ b/lib/initialize.prod.mp.js @@ -6,10 +6,10 @@ require("./utils/wx.polyfill"); var page_mp_1 = require("./page.mp"); var initialize_prod_1 = require("./initialize-prod"); var i18n_1 = require("./platforms/wechatMp/i18n"); -function initialize(storageSchema, createFeatures, contextBuilder, exceptionRouters, connector, checkers, actionDict, i18nOptions) { +function initialize(storageSchema, createFeatures, frontendContextBuilder, exceptionRouters, connector, checkers, actionDict, i18nOptions) { var e_1, _a, _b; if (exceptionRouters === void 0) { exceptionRouters = []; } - var _c = (0, initialize_prod_1.initialize)(storageSchema, createFeatures, contextBuilder, connector, checkers, actionDict), features = _c.features, context = _c.context; + var features = (0, initialize_prod_1.initialize)(storageSchema, createFeatures, frontendContextBuilder, connector, checkers, actionDict).features; var exceptionRouterDict = {}; try { for (var exceptionRouters_1 = tslib_1.__values(exceptionRouters), exceptionRouters_1_1 = exceptionRouters_1.next(); !exceptionRouters_1_1.done; exceptionRouters_1_1 = exceptionRouters_1.next()) { @@ -30,14 +30,15 @@ function initialize(storageSchema, createFeatures, contextBuilder, exceptionRout var i18n = (0, i18n_1.getI18next)(i18nOptions); Object.assign(global, { OakPage: function (options) { - return (0, page_mp_1.createPage)(options, features, exceptionRouterDict, context); + return (0, page_mp_1.createPage)(options, features, exceptionRouterDict); }, OakComponent: function (options) { - return (0, page_mp_1.createComponent)(options, features, exceptionRouterDict, context); + return (0, page_mp_1.createComponent)(options, features, exceptionRouterDict); }, }); return { i18n: i18n, + features: features, }; } exports.initialize = initialize; diff --git a/lib/initialize.prod.web.d.ts b/lib/initialize.prod.web.d.ts index 6ddfb20a..701542f8 100644 --- a/lib/initialize.prod.web.d.ts +++ b/lib/initialize.prod.web.d.ts @@ -8,6 +8,16 @@ import { ActionDictOfEntityDict } from 'oak-domain/lib/types/Action'; import { CommonAspectDict } from 'oak-common-aspect'; import { ExceptionRouters } from './types/ExceptionRoute'; import { I18nOptions } from './platforms/web/i18n'; -export declare function initialize, AD extends Record>, FD extends Record>>>(storageSchema: StorageSchema, createFeatures: (aspectWrapper: AspectWrapper, basicFeatures: BasicFeatures>, context: Cxt) => FD, contextBuilder: (cxtString?: string) => (store: RowStore) => Cxt, exceptionRouters: ExceptionRouters | undefined, connector: Connector, checkers?: Array>, actionDict?: ActionDictOfEntityDict, i18nOptions?: I18nOptions): { +export declare function initialize, AD extends Record>, FD extends Record>>>(storageSchema: StorageSchema, createFeatures: (aspectWrapper: AspectWrapper, basicFeatures: BasicFeatures>) => FD, frontendContextBuilder: (features: FD & BasicFeatures>) => (store: RowStore) => Cxt, exceptionRouters: ExceptionRouters | undefined, connector: Connector, checkers?: Array>, actionDict?: ActionDictOfEntityDict, i18nOptions?: I18nOptions): { i18n: import("i18next").i18n; + features: { + cache: import(".").Cache>; + location: import("./features/location").Location>; + runningTree: import("./features/runningTree").RunningTree>; + locales: import("./features/locales").Locales>; + eventBus: import("./features/eventBus").EventBus>; + localStorage: import(".").LocalStorage>; + notification: import("./features/notification").Notification>; + message: import("./features/message").Message>; + } & FD; }; diff --git a/lib/initialize.prod.web.js b/lib/initialize.prod.web.js index 38666292..b63f9ff0 100644 --- a/lib/initialize.prod.web.js +++ b/lib/initialize.prod.web.js @@ -6,10 +6,10 @@ require("./utils/wx.polyfill"); var page_web_1 = require("./page.web"); var initialize_prod_1 = require("./initialize-prod"); var i18n_1 = require("./platforms/web/i18n"); -function initialize(storageSchema, createFeatures, contextBuilder, exceptionRouters, connector, checkers, actionDict, i18nOptions) { +function initialize(storageSchema, createFeatures, frontendContextBuilder, exceptionRouters, connector, checkers, actionDict, i18nOptions) { var e_1, _a, _b; if (exceptionRouters === void 0) { exceptionRouters = []; } - var _c = (0, initialize_prod_1.initialize)(storageSchema, createFeatures, contextBuilder, connector, checkers, actionDict), features = _c.features, context = _c.context; + var features = (0, initialize_prod_1.initialize)(storageSchema, createFeatures, frontendContextBuilder, connector, checkers, actionDict).features; var exceptionRouterDict = {}; try { for (var exceptionRouters_1 = tslib_1.__values(exceptionRouters), exceptionRouters_1_1 = exceptionRouters_1.next(); !exceptionRouters_1_1.done; exceptionRouters_1_1 = exceptionRouters_1.next()) { @@ -30,14 +30,15 @@ function initialize(storageSchema, createFeatures, contextBuilder, exceptionRout var i18n = (0, i18n_1.getI18next)(i18nOptions); Object.assign(global, { OakPage: function (options) { - return (0, page_web_1.createPage)(options, features, exceptionRouterDict, context); + return (0, page_web_1.createPage)(options, features, exceptionRouterDict); }, OakComponent: function (options) { - return (0, page_web_1.createComponent)(options, features, exceptionRouterDict, context); + return (0, page_web_1.createComponent)(options, features, exceptionRouterDict); }, }); return { i18n: i18n, + features: features, }; } exports.initialize = initialize; diff --git a/lib/page.common.d.ts b/lib/page.common.d.ts index 1feb03ee..bcbc96d0 100644 --- a/lib/page.common.d.ts +++ b/lib/page.common.d.ts @@ -17,4 +17,4 @@ export declare type ComponentThisType(): OakHiddenComponentMethods & ComponentThisType; export declare function makeCommonComponentMethods, AD extends Record>, FD extends Record>>, FormedData extends WechatMiniprogram.Component.DataOption, Proj extends ED[T]['Selection']['data'], IsList extends boolean, TData extends WechatMiniprogram.Component.DataOption = {}, TProperty extends WechatMiniprogram.Component.PropertyOption = {}, TMethod extends WechatMiniprogram.Component.MethodOption = {}>(features: BasicFeatures> & FD, exceptionRouterDict: Record, formData: OakPageOption['formData']): Omit, 'navigateTo' | 'navigateBack' | 'resolveInput' | 'redirectTo' | 't'> & ComponentThisType; export declare function makeListComponentMethods, AD extends Record>, FD extends Record>>, FormedData extends WechatMiniprogram.Component.DataOption, IsList extends boolean, TData extends WechatMiniprogram.Component.DataOption = {}, TProperty extends WechatMiniprogram.Component.PropertyOption = {}, TMethod extends WechatMiniprogram.Component.MethodOption = {}>(features: BasicFeatures> & FD): OakListComponentMethods & ComponentThisType; -export declare function makePageMethods, AD extends Record>, FD extends Record>>, FormedData extends WechatMiniprogram.Component.DataOption, Proj extends ED[T]['Selection']['data'], IsList extends boolean, TData extends WechatMiniprogram.Component.DataOption = {}, TProperty extends WechatMiniprogram.Component.PropertyOption = {}, TMethod extends WechatMiniprogram.Component.MethodOption = {}>(features: BasicFeatures> & FD, options: OakPageOption, context: Cxt): OakPageMethods & ComponentThisType; +export declare function makePageMethods, AD extends Record>, FD extends Record>>, FormedData extends WechatMiniprogram.Component.DataOption, Proj extends ED[T]['Selection']['data'], IsList extends boolean, TData extends WechatMiniprogram.Component.DataOption = {}, TProperty extends WechatMiniprogram.Component.PropertyOption = {}, TMethod extends WechatMiniprogram.Component.MethodOption = {}>(features: BasicFeatures> & FD, options: OakPageOption): OakPageMethods & ComponentThisType; diff --git a/lib/page.common.js b/lib/page.common.js index e47d906e..0b0ce550 100644 --- a/lib/page.common.js +++ b/lib/page.common.js @@ -677,7 +677,7 @@ function makeListComponentMethods(features) { }; } exports.makeListComponentMethods = makeListComponentMethods; -function makePageMethods(features, options, context) { +function makePageMethods(features, options) { return { refresh: function () { return tslib_1.__awaiter(this, void 0, void 0, function () { @@ -775,7 +775,7 @@ function makePageMethods(features, options, context) { var _this = this; return tslib_1.__generator(this, function (_a) { return [2 /*return*/, new Promise(function (resolve, reject) { return tslib_1.__awaiter(_this, void 0, void 0, function () { - var _a, oakId, oakEntity, oakPath, oakProjection, oakParent, oakSorters, oakFilters, oakIsPicker, oakFrom, oakActions, props, filters, oakFilters2, _loop_1, _b, _c, ele, proj, projection_1, sorters, oakSorters2, _loop_2, _d, _e, ele, oakPath2, path2_1, node, _f, e_3; + var _a, oakId, oakEntity, oakPath, oakProjection, oakParent, oakSorters, oakFilters, oakIsPicker, oakFrom, oakActions, props, filters, oakFilters2, _loop_1, _b, _c, ele, proj, projection_1, sorters, oakSorters2, _loop_2, _d, _e, ele, oakPath2, path2, node, _f, e_3; var e_4, _g, e_5, _h; var _this = this; var _j; @@ -876,11 +876,11 @@ function makePageMethods(features, options, context) { } oakPath2 = oakPath || options.path; (0, assert_1.assert)(oakPath2, '没有正确的path信息,请检查是否配置正确'); - path2_1 = oakParent + path2 = oakParent ? "".concat(oakParent, ":").concat(oakPath2) : oakPath2; return [4 /*yield*/, features.runningTree.createNode({ - path: path2_1, + path: path2, entity: (oakEntity || options.entity), isList: options.isList, isPicker: oakIsPicker, @@ -895,7 +895,7 @@ function makePageMethods(features, options, context) { // const oakFullpath = oakParent ? `${oakParent}.${oakPath || options.path}` : oakPath || options.path; return [4 /*yield*/, this.setState({ oakEntity: node.getEntity(), - oakFullpath: path2_1, + oakFullpath: path2, oakFrom: oakFrom, newOakActions: oakActions && JSON.parse(oakActions).length > 0 @@ -907,7 +907,6 @@ function makePageMethods(features, options, context) { return tslib_1.__generator(this, function (_c) { switch (_c.label) { case 0: - context.setScene(path2_1); this.refresh(); _a = ((_b = options.methods) === null || _b === void 0 ? void 0 : _b.onLoad); if (!_a) return [3 /*break*/, 2]; diff --git a/lib/page.mp.d.ts b/lib/page.mp.d.ts index c6da0a72..0ad19c02 100644 --- a/lib/page.mp.d.ts +++ b/lib/page.mp.d.ts @@ -6,5 +6,5 @@ import { BasicFeatures } from './features'; import { ExceptionHandler } from './types/ExceptionRoute'; import { Feature } from './types/Feature'; import { OakComponentOption, OakPageOption } from './types/Page'; -export declare function createPage, AD extends Record>, FD extends Record>>, Proj extends ED[T]['Selection']['data'], FormedData extends WechatMiniprogram.Component.DataOption, IsList extends boolean, TData extends WechatMiniprogram.Component.DataOption = {}, TProperty extends WechatMiniprogram.Component.PropertyOption = {}, TMethod extends WechatMiniprogram.Component.MethodOption = {}>(options: OakPageOption, features: BasicFeatures> & FD, exceptionRouterDict: Record, context: Cxt): string; -export declare function createComponent, AD extends Record>, FD extends Record>>, FormedData extends WechatMiniprogram.Component.DataOption, IsList extends boolean, TData extends WechatMiniprogram.Component.DataOption = {}, TProperty extends WechatMiniprogram.Component.PropertyOption = {}, TMethod extends WechatMiniprogram.Component.MethodOption = {}>(options: OakComponentOption, features: BasicFeatures> & FD, exceptionRouterDict: Record, context: Cxt): string; +export declare function createPage, AD extends Record>, FD extends Record>>, Proj extends ED[T]['Selection']['data'], FormedData extends WechatMiniprogram.Component.DataOption, IsList extends boolean, TData extends WechatMiniprogram.Component.DataOption = {}, TProperty extends WechatMiniprogram.Component.PropertyOption = {}, TMethod extends WechatMiniprogram.Component.MethodOption = {}>(options: OakPageOption, features: BasicFeatures> & FD, exceptionRouterDict: Record): string; +export declare function createComponent, AD extends Record>, FD extends Record>>, FormedData extends WechatMiniprogram.Component.DataOption, IsList extends boolean, TData extends WechatMiniprogram.Component.DataOption = {}, TProperty extends WechatMiniprogram.Component.PropertyOption = {}, TMethod extends WechatMiniprogram.Component.MethodOption = {}>(options: OakComponentOption, features: BasicFeatures> & FD, exceptionRouterDict: Record): string; diff --git a/lib/page.mp.js b/lib/page.mp.js index 7960ca02..f4f436a6 100644 --- a/lib/page.mp.js +++ b/lib/page.mp.js @@ -156,8 +156,8 @@ function makeCommonComponentMethods(features, exceptionRouterDict, formData) { }); } }, (0, page_common_1.makeCommonComponentMethods)(features, exceptionRouterDict, formData)); } -function makePageMethods(features, options, context) { - var _a = (0, page_common_1.makePageMethods)(features, options, context), onPullDownRefresh = _a.onPullDownRefresh, onLoad = _a.onLoad, rest = tslib_1.__rest(_a, ["onPullDownRefresh", "onLoad"]); +function makePageMethods(features, options) { + var _a = (0, page_common_1.makePageMethods)(features, options), onPullDownRefresh = _a.onPullDownRefresh, onLoad = _a.onLoad, rest = tslib_1.__rest(_a, ["onPullDownRefresh", "onLoad"]); return tslib_1.__assign({ onPullDownRefresh: function () { return tslib_1.__awaiter(this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) { @@ -205,12 +205,12 @@ function makePageMethods(features, options, context) { }); } }, rest); } -function createPage(options, features, exceptionRouterDict, context) { +function createPage(options, features, exceptionRouterDict) { var formData = options.formData, isList = options.isList; var hiddenMethods = (0, page_common_1.makeHiddenComponentMethods)(); var commonMethods = makeCommonComponentMethods(features, exceptionRouterDict, formData); var listMethods = (0, page_common_1.makeListComponentMethods)(features); - var _a = makePageMethods(features, options, context), onLoad = _a.onLoad, onPullDownRefresh = _a.onPullDownRefresh, onReachBottom = _a.onReachBottom, restPageMethods = tslib_1.__rest(_a, ["onLoad", "onPullDownRefresh", "onReachBottom"]); + var _a = makePageMethods(features, options), onLoad = _a.onLoad, onPullDownRefresh = _a.onPullDownRefresh, onReachBottom = _a.onReachBottom, restPageMethods = tslib_1.__rest(_a, ["onLoad", "onPullDownRefresh", "onReachBottom"]); var methods = options.methods, lifetimes = options.lifetimes, pageLifetimes = options.pageLifetimes; return Component({ data: Object.assign({}, options.data, { @@ -330,7 +330,6 @@ function createPage(options, features, exceptionRouterDict, context) { show: function () { this.subscribe(); if (this.data.oakFullpath) { - context.setScene(this.data.oakFullpath); this.reRender(); } (pageLifetimes === null || pageLifetimes === void 0 ? void 0 : pageLifetimes.show) && pageLifetimes.show.call(this); @@ -346,7 +345,7 @@ function createPage(options, features, exceptionRouterDict, context) { }); } exports.createPage = createPage; -function createComponent(options, features, exceptionRouterDict, context) { +function createComponent(options, features, exceptionRouterDict) { var formData = options.formData, isList = options.isList, entity = options.entity, methods = options.methods, lifetimes = options.lifetimes, pageLifetimes = options.pageLifetimes, data = options.data, properties = options.properties, actions = options.actions, observers = options.observers, restOptions = tslib_1.__rest(options, ["formData", "isList", "entity", "methods", "lifetimes", "pageLifetimes", "data", "properties", "actions", "observers"]); var hiddenMethods = (0, page_common_1.makeHiddenComponentMethods)(); var commonMethods = makeCommonComponentMethods(features, exceptionRouterDict, formData); diff --git a/lib/page.web.d.ts b/lib/page.web.d.ts index b589a60c..5a23b278 100644 --- a/lib/page.web.d.ts +++ b/lib/page.web.d.ts @@ -7,5 +7,5 @@ import { BasicFeatures } from './features'; import { ExceptionHandler } from './types/ExceptionRoute'; import { Feature } from './types/Feature'; import { OakComponentOption, OakPageOption } from './types/Page'; -export declare function createPage, AD extends Record>, FD extends Record>>, Proj extends ED[T]['Selection']['data'], FormedData extends WechatMiniprogram.Component.DataOption, IsList extends boolean, TData extends WechatMiniprogram.Component.DataOption = {}, TProperty extends WechatMiniprogram.Component.PropertyOption = {}, TMethod extends WechatMiniprogram.Component.MethodOption = {}>(options: OakPageOption, features: BasicFeatures> & FD, exceptionRouterDict: Record, context: Cxt): React.ForwardRefExoticComponent>; -export declare function createComponent, AD extends Record>, FD extends Record>>, FormedData extends WechatMiniprogram.Component.DataOption, IsList extends boolean, TData extends WechatMiniprogram.Component.DataOption = {}, TProperty extends WechatMiniprogram.Component.PropertyOption = {}, TMethod extends WechatMiniprogram.Component.MethodOption = {}>(options: OakComponentOption, features: BasicFeatures> & FD, exceptionRouterDict: Record, context: Cxt): React.ForwardRefExoticComponent>; +export declare function createPage, AD extends Record>, FD extends Record>>, Proj extends ED[T]['Selection']['data'], FormedData extends WechatMiniprogram.Component.DataOption, IsList extends boolean, TData extends WechatMiniprogram.Component.DataOption = {}, TProperty extends WechatMiniprogram.Component.PropertyOption = {}, TMethod extends WechatMiniprogram.Component.MethodOption = {}>(options: OakPageOption, features: BasicFeatures> & FD, exceptionRouterDict: Record): React.ForwardRefExoticComponent>; +export declare function createComponent, AD extends Record>, FD extends Record>>, FormedData extends WechatMiniprogram.Component.DataOption, IsList extends boolean, TData extends WechatMiniprogram.Component.DataOption = {}, TProperty extends WechatMiniprogram.Component.PropertyOption = {}, TMethod extends WechatMiniprogram.Component.MethodOption = {}>(options: OakComponentOption, features: BasicFeatures> & FD, exceptionRouterDict: Record): React.ForwardRefExoticComponent>; diff --git a/lib/page.web.js b/lib/page.web.js index e5cb94b2..a520fbcb 100644 --- a/lib/page.web.js +++ b/lib/page.web.js @@ -95,8 +95,8 @@ function makeCommonComponentMethods(features, exceptionRouterDict, formData) { return this.props.navigate(url2, { replace: true, state: state }); } }, (0, page_common_1.makeCommonComponentMethods)(features, exceptionRouterDict, formData)); } -function makePageMethods(features, options, context) { - var _a = (0, page_common_1.makePageMethods)(features, options, context), onPullDownRefresh = _a.onPullDownRefresh, rest = tslib_1.__rest(_a, ["onPullDownRefresh"]); +function makePageMethods(features, options) { + var _a = (0, page_common_1.makePageMethods)(features, options), onPullDownRefresh = _a.onPullDownRefresh, rest = tslib_1.__rest(_a, ["onPullDownRefresh"]); return tslib_1.__assign({ onPullDownRefresh: function () { return tslib_1.__awaiter(this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) { @@ -175,12 +175,12 @@ function makeMiniprogramCompatibleFunctions() { }; } var DEFAULT_REACH_BOTTOM_DISTANCE = 50; -function createPage(options, features, exceptionRouterDict, context) { +function createPage(options, features, exceptionRouterDict) { var _a = options, formData = _a.formData, isList = _a.isList, render = _a.render; var hiddenMethods = (0, page_common_1.makeHiddenComponentMethods)(); var commonMethods = makeCommonComponentMethods(features, exceptionRouterDict, formData); var listMethods = (0, page_common_1.makeListComponentMethods)(features); - var _b = makePageMethods(features, options, context), onLoad = _b.onLoad, onPullDownRefresh = _b.onPullDownRefresh, onReachBottom = _b.onReachBottom, restPageMethods = tslib_1.__rest(_b, ["onLoad", "onPullDownRefresh", "onReachBottom"]); + var _b = makePageMethods(features, options), onLoad = _b.onLoad, onPullDownRefresh = _b.onPullDownRefresh, onReachBottom = _b.onReachBottom, restPageMethods = tslib_1.__rest(_b, ["onLoad", "onPullDownRefresh", "onReachBottom"]); var methods = options.methods, lifetimes = options.lifetimes, pageLifetimes = options.pageLifetimes, data = options.data, observers = options.observers; var fn = translateObservers(observers).fn; var OakPageWrapper = /** @class */ (function (_super) { @@ -218,7 +218,6 @@ function createPage(options, features, exceptionRouterDict, context) { _d)); } } - context.setScene(options.path); (lifetimes === null || lifetimes === void 0 ? void 0 : lifetimes.created) && lifetimes.created.call(_this); return _this; } @@ -305,7 +304,7 @@ function createPage(options, features, exceptionRouterDict, context) { return (0, web_1.withRouter)(OakPageWrapper, false, options.path); } exports.createPage = createPage; -function createComponent(options, features, exceptionRouterDict, context) { +function createComponent(options, features, exceptionRouterDict) { var _a = options, formData = _a.formData, isList = _a.isList, entity = _a.entity, methods = _a.methods, lifetimes = _a.lifetimes, pageLifetimes = _a.pageLifetimes, data = _a.data, properties = _a.properties, observers = _a.observers, render = _a.render; var hiddenMethods = (0, page_common_1.makeHiddenComponentMethods)(); var commonMethods = makeCommonComponentMethods(features, exceptionRouterDict, formData); diff --git a/package.json b/package.json index b4407446..2549ed8d 100644 --- a/package.json +++ b/package.json @@ -66,5 +66,5 @@ "test": "ts-node ./test/test.ts", "prepare": "rimraf node_modules/react & rimraf node_modules/react-dom & rimraf node_modules/react-router" }, - "main": "lib/index" + "main": "src/index" } diff --git a/src/cacheStore/CacheStore.ts b/src/cacheStore/CacheStore.ts index 25b61904..f5f79713 100644 --- a/src/cacheStore/CacheStore.ts +++ b/src/cacheStore/CacheStore.ts @@ -15,15 +15,13 @@ export class CacheStore< constructor( storageSchema: StorageSchema, - contextBuilder: ( - cxtString: string - ) => (store: CacheStore) => Cxt, + contextBuilder: () => (store: CacheStore) => Cxt, getFullDataFn?: () => any, resetInitialDataFn?: () => void ) { super(storageSchema); - this.executor = new TriggerExecutor(async (cxtStr) => - contextBuilder(cxtStr)(this) + this.executor = new TriggerExecutor(async () => + contextBuilder()(this) ); this.getFullDataFn = getFullDataFn; this.resetInitialDataFn = resetInitialDataFn; diff --git a/src/debugStore/DebugStore.ts b/src/debugStore/DebugStore.ts index cedf671e..d79b780f 100644 --- a/src/debugStore/DebugStore.ts +++ b/src/debugStore/DebugStore.ts @@ -16,9 +16,9 @@ interface DebugStoreSelectOption extends SelectOption { export class DebugStore> extends TreeStore { private executor: TriggerExecutor; private rwLock: RWLock; - constructor(storageSchema: StorageSchema, contextBuilder: (cxtString?: string) => (store: RowStore) => Cxt) { + constructor(storageSchema: StorageSchema, contextBuilder: (cxtString?: string) => (store: RowStore) => Promise) { super(storageSchema); - this.executor = new TriggerExecutor(async (cxtString) => contextBuilder(cxtString)(this)); + this.executor = new TriggerExecutor((cxtString) => contextBuilder(cxtString)(this)); this.rwLock = new RWLock(); } diff --git a/src/debugStore/index.ts b/src/debugStore/index.ts index 5b3e00e8..ccf0e651 100644 --- a/src/debugStore/index.ts +++ b/src/debugStore/index.ts @@ -1,4 +1,4 @@ -import { DebugStore } from './debugStore'; +import { DebugStore } from './DebugStore'; import { Checker, Trigger, StorageSchema, FormCreateData, Context, EntityDict, RowStore, ActionDictOfEntityDict, Watcher, BBWatcher, WBWatcher, OperationResult @@ -136,13 +136,13 @@ export function clearMaterializedData() { * @param watchers */ function initializeWatchers>( - store: DebugStore, contextBuilder: (cxtString?: string) => (store: RowStore) => Cxt, watchers: Array>) { + store: DebugStore, contextBuilder: (cxtString?: string) => (store: RowStore) => Promise, watchers: Array>) { let count = 0; async function doWatchers() { count++; const start = Date.now(); - const context = contextBuilder()(store); + const context = await contextBuilder()(store); for (const w of watchers) { await context.begin(); try { @@ -208,7 +208,7 @@ function initializeWatchers>( storageSchema: StorageSchema, - contextBuilder: (cxtString?: string) => (store: RowStore) => Cxt, + contextBuilder: (cxtString?: string) => (store: RowStore) => Promise, triggers: Array>, checkers: Array>, watchers: Array>, diff --git a/src/features/cache.ts b/src/features/cache.ts index b96433df..f363cf32 100644 --- a/src/features/cache.ts +++ b/src/features/cache.ts @@ -1,4 +1,4 @@ -import { EntityDict, OperateOption, SelectOption, OpRecord, Context, AspectWrapper } from 'oak-domain/lib/types'; +import { EntityDict, OperateOption, SelectOption, OpRecord, Context, AspectWrapper, SelectionResult } from 'oak-domain/lib/types'; import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain'; import { reinforceSelection } from 'oak-domain/lib/store/selection'; import { CommonAspectDict } from 'oak-common-aspect'; @@ -13,25 +13,16 @@ export class Cache< Cxt extends Context, AD extends CommonAspectDict > extends Feature { - cacheStore: CacheStore; - context: Cxt; + cacheStore?: CacheStore; private syncEventsCallbacks: Array< (opRecords: OpRecord[]) => Promise >; - private contextBuilder: () => Cxt; + private contextBuilder?: () => Cxt; private syncLock: RWLock; - constructor( - aspectWrapper: AspectWrapper, - context: Cxt, - cacheStore: CacheStore, - contextBuilder: () => Cxt - ) { + constructor(aspectWrapper: AspectWrapper) { super(aspectWrapper); - this.cacheStore = cacheStore; - this.context = context; this.syncEventsCallbacks = []; - this.contextBuilder = contextBuilder; this.syncLock = new RWLock(); // 在这里把wrapper的返回opRecords截取到并同步到cache中 @@ -49,6 +40,15 @@ export class Cache< }; } + /** + * 目前context和cache会形成循环依赖,这里不太好处理,只能先让contextBuilder后注入 + * @param contextBuilder + */ + init(contextBuilder: () => Cxt, store: CacheStore) { + this.contextBuilder = contextBuilder; + this.cacheStore = store; + } + @Action async refresh( entity: T, @@ -56,7 +56,7 @@ export class Cache< option?: OP, getCount?: true ) { - reinforceSelection(this.cacheStore.getSchema() ,entity, selection); + reinforceSelection(this.cacheStore!.getSchema() ,entity, selection); const { result } = await this.getAspectWrapper().exec('select', { entity, selection, @@ -83,9 +83,9 @@ export class Cache< private async sync(records: OpRecord[]) { // sync会异步并发的调用,不能用this.context; - const context = this.contextBuilder(); + const context = this.contextBuilder!(); await this.syncLock.acquire('X'); - await this.cacheStore.sync(records, context); + await this.cacheStore!.sync(records, context); this.syncLock.release(); // 唤起同步注册的回调 @@ -106,25 +106,25 @@ export class Cache< entity: T, operation: ED[T]['Operation'], ) { - let result: Awaited>; - await this.context.begin(); + const context = this.contextBuilder!(); + await context.begin(); try { - result = await this.cacheStore.operate( + await this.cacheStore!.operate( entity, operation, - this.context, + context, { dontCollect: true, dontCreateOper: true, } ); - await this.context.rollback(); + await context.rollback(); } catch (err) { - await this.context.rollback(); + await context.rollback(); throw err; } - return result; + return true; } /** @@ -137,13 +137,14 @@ export class Cache< entity: keyof ED, operation: ED[keyof ED]['Operation'] }>) { - let result: Awaited>; - await this.context.begin(); + let result: SelectionResult; + const context = this.contextBuilder!(); + await context.begin(); for (const oper of opers) { - await this.cacheStore.operate( + await this.cacheStore!.operate( oper.entity, oper.operation, - this.context, + context, { dontCollect: true, dontCreateOper: true, @@ -153,11 +154,11 @@ export class Cache< } while (true) { try { - result = await this.cacheStore.select(entity, selection, this.context, { + result = await this.cacheStore!.select(entity, selection, context, { dontCollect: true, }); - await this.context.rollback(); + await context.rollback(); return result; } catch (err) { if (err instanceof OakRowUnexistedException) { @@ -165,7 +166,7 @@ export class Cache< await this.getAspectWrapper().exec('fetchRows', missedRows); } else { - await this.context.rollback(); + await context.rollback(); throw err; } } @@ -177,17 +178,18 @@ export class Cache< selection: S, params?: SelectOption ) { - const { result } = await this.cacheStore.select( + const context = this.contextBuilder!(); + const { result } = await this.cacheStore!.select( entity, selection, - this.context, + context, {} ); return result; } judgeRelation(entity: keyof ED, attr: string) { - return this.cacheStore.judgeRelation(entity, attr); + return this.cacheStore!.judgeRelation(entity, attr); } bindOnSync(callback: (opRecords: OpRecord[]) => Promise) { @@ -199,14 +201,14 @@ export class Cache< } getCachedData() { - return this.cacheStore.getCurrentData(); + return this.cacheStore!.getCurrentData(); } getFullData() { - return this.cacheStore.getFullData(); + return this.cacheStore!.getFullData(); } resetInitialData() { - return this.cacheStore.resetInitialData(); + return this.cacheStore!.resetInitialData(); } } diff --git a/src/features/index.ts b/src/features/index.ts index 05fb842f..0d322103 100644 --- a/src/features/index.ts +++ b/src/features/index.ts @@ -11,15 +11,11 @@ import { EventBus } from './eventBus'; import { LocalStorage } from './localStorage'; import { Notification } from './notification'; import { Message } from './message'; -import { CacheStore } from '../cacheStore/CacheStore'; export function initialize, AD extends CommonAspectDict> ( aspectWrapper: AspectWrapper, - storageSchema: StorageSchema, - context: Cxt, - cacheStore: CacheStore, - contextBuilder: () => Cxt): BasicFeatures { - const cache = new Cache(aspectWrapper, context, cacheStore, contextBuilder); + storageSchema: StorageSchema) { + const cache = new Cache(aspectWrapper); const location = new Location(aspectWrapper); const runningTree = new RunningTree(aspectWrapper, cache, storageSchema); const locales = new Locales(aspectWrapper); diff --git a/src/initialize-dev.ts b/src/initialize-dev.ts index 8239fec1..38d411dc 100644 --- a/src/initialize-dev.ts +++ b/src/initialize-dev.ts @@ -17,7 +17,7 @@ import { createDynamicTriggers } from 'oak-domain/lib/triggers/index'; import { Feature } from './types/Feature'; import { createDebugStore, clearMaterializedData } from './debugStore'; -import { initialize as createBasicFeatures, BasicFeatures } from './features'; +import { BasicFeatures, initialize as initBasicFeatures } from './features'; import { intersection } from 'oak-domain/lib/utils/lodash'; import commonAspectDict from 'oak-common-aspect'; import { ActionDictOfEntityDict } from 'oak-domain/lib/types/Action'; @@ -26,7 +26,6 @@ import { CommonAspectDict } from 'oak-common-aspect'; import { CacheStore } from './cacheStore/CacheStore'; /** - * dev模式下,前后端可以使用同一个Cxt,内部自己区分 * @param storageSchema * @param createFeatures * @param contextBuilder @@ -49,9 +48,9 @@ export function initialize< createFeatures: ( aspectWrapper: AspectWrapper, basicFeatures: BasicFeatures>, - context: Cxt ) => FD, - contextBuilder: (cxtString?: string) => (store: RowStore) => Cxt, + frontendContextBuilder: (features: FD & BasicFeatures>) => (store: RowStore) => Cxt, + backendContextBuilder: (contextStr?: string) => (store: RowStore) => Promise, aspectDict: AD, triggers?: Array>, checkers?: Array>, @@ -61,10 +60,10 @@ export function initialize< }, actionDict?: ActionDictOfEntityDict ) { - let intersect = intersection(Object.keys(commonAspectDict), Object.keys(aspectDict)); - if (intersect.length > 0) { + let intersected = intersection(Object.keys(commonAspectDict), Object.keys(aspectDict)); + if (intersected.length > 0) { throw new Error( - `用户定义的aspect中不能和系统aspect同名:「${intersect.join(',')}」` + `用户定义的aspect中不能和系统aspect同名:「${intersected.join(',')}」` ); } const aspectDict2 = Object.assign({}, commonAspectDict, aspectDict); @@ -72,7 +71,7 @@ export function initialize< const triggers2 = createDynamicTriggers(storageSchema).concat(triggers || []); const debugStore = createDebugStore( storageSchema, - contextBuilder, + backendContextBuilder, triggers2, checkers2, watchers || [], @@ -80,12 +79,52 @@ export function initialize< actionDict ); + const wrapper: AspectWrapper = { + } as any; + + const basicFeatures = initBasicFeatures(wrapper, storageSchema); + const userDefinedfeatures = createFeatures(wrapper, basicFeatures); + + intersected = intersection(Object.keys(basicFeatures), Object.keys(userDefinedfeatures)); + if (intersected.length > 0) { + throw new Error( + `用户定义的feature中不能和系统feature同名:「${intersected.join( + ',' + )}」` + ); + } + const features = Object.assign(basicFeatures, userDefinedfeatures); + + // feature 和 wrapper在这里又形成了相互调用 + wrapper.exec = async (name, params) => { + const context = frontendContextBuilder(features)(cacheStore); + const str = await context.toString(); + const contextBackend = await backendContextBuilder(str)(debugStore); + await contextBackend.begin(); + let result; + try { + result = await aspectDict2[name](params, contextBackend); + await contextBackend.commit(); + } catch (err) { + await contextBackend.rollback(); + throw err; + } + return { + result, + opRecords: contextBackend.opRecords, + }; + }; + const cacheStore = new CacheStore( storageSchema, - contextBuilder, + () => frontendContextBuilder(features), () => debugStore.getCurrentData(), () => clearMaterializedData(), ); + + // cache这个feature依赖于cacheStore和contextBuilder,后注入 + basicFeatures.cache.init(() => frontendContextBuilder(features)(cacheStore), cacheStore); + checkers2.forEach((checker) => cacheStore.registerChecker(checker)); if (actionDict) { const { checkers: adCheckers } = analyzeActionDefDict( @@ -94,55 +133,8 @@ export function initialize< ); adCheckers.forEach((checker) => cacheStore.registerChecker(checker)); } - const context = contextBuilder()(cacheStore); - - const wrapper: AspectWrapper = { - exec: async (name, params) => { - const str = await context.toString(); - const contextBackend = contextBuilder(str)(debugStore); - await contextBackend.begin(); - let result; - try { - result = await aspectDict2[name](params, contextBackend); - await contextBackend.commit(); - } catch (err) { - await contextBackend.rollback(); - throw err; - } - return { - result, - opRecords: contextBackend.opRecords, - }; - }, - }; - - const basicFeatures = createBasicFeatures( - wrapper, - storageSchema, - context, - cacheStore, - () => contextBuilder()(cacheStore) - ); - - // basicFeatures.runningNode.setStorageSchema(storageSchema); - - const userDefinedFeatures = createFeatures(wrapper, basicFeatures, context); - - intersect = intersection( - Object.keys(basicFeatures), - Object.keys(userDefinedFeatures) - ); - if (intersect.length > 0) { - throw new Error( - `用户定义的feature中不能和系统feature同名:「${intersect.join( - ',' - )}」` - ); - } - const features = Object.assign(basicFeatures, userDefinedFeatures); return { features, - context, }; } diff --git a/src/initialize-prod.ts b/src/initialize-prod.ts index 0cfc9bf1..8467ebc7 100644 --- a/src/initialize-prod.ts +++ b/src/initialize-prod.ts @@ -12,7 +12,7 @@ import { EntityDict } from 'oak-domain/lib/types/Entity'; import { Feature } from './types/Feature'; -import { initialize as createBasicFeatures, BasicFeatures } from './features'; +import { initialize as initBasicFeatures, BasicFeatures } from './features'; import { intersection } from 'oak-domain/lib/utils/lodash'; import { ActionDictOfEntityDict } from 'oak-domain/lib/types/Action'; import { analyzeActionDefDict } from 'oak-domain/lib/store/actionDef'; @@ -50,15 +50,50 @@ export function initialize< createFeatures: ( aspectWrapper: AspectWrapper, basicFeatures: BasicFeatures>, - context: Cxt ) => FD, - contextBuilder: (cxtString?: string) => (store: RowStore) => Cxt, + frontendContextBuilder: (features: FD & BasicFeatures>) => (store: RowStore) => Cxt, connector: Connector, checkers?: Array>, actionDict?: ActionDictOfEntityDict ) { - const cacheStore = new CacheStore(storageSchema, contextBuilder); const checkers2 = createDynamicCheckers(storageSchema).concat(checkers || []); + + const wrapper: AspectWrapper> = { + } as any; + + const basicFeatures = initBasicFeatures>( + wrapper, + storageSchema + ); + + const userDefinedfeatures = createFeatures(wrapper, basicFeatures); + + const intersected = intersection(Object.keys(basicFeatures), Object.keys(userDefinedfeatures)); + if (intersected.length > 0) { + throw new Error( + `用户定义的feature中不能和系统feature同名:「${intersected.join( + ',' + )}」` + ); + } + const features = Object.assign(basicFeatures, userDefinedfeatures); + const cacheStore = new CacheStore( + storageSchema, + () => frontendContextBuilder(features) + ); + + wrapper.exec = async (name, params) => { + const context = frontendContextBuilder(features)(cacheStore); + const { result, opRecords } = await connector.callAspect(name as string, params, context); + return { + result, + opRecords, + }; + }, + + // cache这个feature依赖于cacheStore和contextBuilder,后注入 + basicFeatures.cache.init(() => frontendContextBuilder(features)(cacheStore), cacheStore); + checkers2.forEach((checker) => cacheStore.registerChecker(checker)); if (actionDict) { const { checkers: adCheckers } = analyzeActionDefDict( @@ -67,42 +102,8 @@ export function initialize< ); adCheckers.forEach((checker) => cacheStore.registerChecker(checker)); } - const context = contextBuilder()(cacheStore); - - const wrapper: AspectWrapper> = { - exec: async (name, params) => { - const { result, opRecords } = await connector.callAspect(name as string, params, context); - return { - result, - opRecords, - }; - }, - }; - - const basicFeatures = createBasicFeatures>( - wrapper, - storageSchema, - context, - cacheStore, - () => contextBuilder()(cacheStore) - ); - - // basicFeatures.runningNode.setStorageSchema(storageSchema); - - const userDefinedfeatures = createFeatures(wrapper, basicFeatures, context); - - const intersect = intersection(Object.keys(basicFeatures), Object.keys(userDefinedfeatures)); - if (intersect.length > 0) { - throw new Error( - `用户定义的feature中不能和系统feature同名:「${intersect.join( - ',' - )}」` - ); - } - const features = Object.assign(basicFeatures, userDefinedfeatures); return { features, - context, }; } diff --git a/src/initialize.dev.mp.ts b/src/initialize.dev.mp.ts index dff3e691..9f5c1f66 100644 --- a/src/initialize.dev.mp.ts +++ b/src/initialize.dev.mp.ts @@ -34,9 +34,9 @@ export function initialize< createFeatures: ( aspectWrapper: AspectWrapper, basicFeatures: BasicFeatures>, - context: Cxt ) => FD, - contextBuilder: (cxtString?: string) => (store: RowStore) => Cxt, + frontendContextBuilder: (features: FD & BasicFeatures>) => (store: RowStore) => Cxt, + backendContextBuilder: (contextStr?: string) => (store: RowStore) => Promise, aspectDict: AD, exceptionRouters: ExceptionRouters = [], triggers?: Array>, @@ -48,10 +48,11 @@ export function initialize< actionDict?: ActionDictOfEntityDict, i18nOptions?: I18nOptions ) { - const { features, context } = initDev( + const { features } = initDev( storageSchema, createFeatures, - contextBuilder, + frontendContextBuilder, + backendContextBuilder, aspectDict, triggers, checkers, @@ -105,7 +106,7 @@ export function initialize< TData, TProperty, TMethod - >(options, features, exceptionRouterDict, context), + >(options, features, exceptionRouterDict), OakComponent: < T extends keyof ED, FormedData extends WechatMiniprogram.Component.DataOption, @@ -138,10 +139,11 @@ export function initialize< TData, TProperty, TMethod - >(options, features, exceptionRouterDict, context), + >(options, features, exceptionRouterDict), }); return { i18n, + features, }; } diff --git a/src/initialize.dev.web.ts b/src/initialize.dev.web.ts index 1927a498..bb484405 100644 --- a/src/initialize.dev.web.ts +++ b/src/initialize.dev.web.ts @@ -34,9 +34,9 @@ export function initialize< createFeatures: ( aspectWrapper: AspectWrapper, basicFeatures: BasicFeatures>, - context: Cxt ) => FD, - contextBuilder: (cxtString?: string) => (store: RowStore) => Cxt, + frontendContextBuilder: (features: FD & BasicFeatures>) => (store: RowStore) => Cxt, + backendContextBuilder: (contextStr?: string) => (store: RowStore) => Promise, aspectDict: AD, exceptionRouters: ExceptionRouters = [], triggers?: Array>, @@ -48,10 +48,11 @@ export function initialize< actionDict?: ActionDictOfEntityDict, i18nOptions?: I18nOptions ) { - const { features, context } = initDev( + const { features } = initDev( storageSchema, createFeatures, - contextBuilder, + frontendContextBuilder, + backendContextBuilder, aspectDict, triggers, checkers, @@ -106,7 +107,7 @@ export function initialize< TData, TProperty, TMethod - >(options, features, exceptionRouterDict, context), + >(options, features, exceptionRouterDict), OakComponent: < T extends keyof ED, FormedData extends WechatMiniprogram.Component.DataOption, @@ -139,10 +140,11 @@ export function initialize< TData, TProperty, TMethod - >(options, features, exceptionRouterDict, context), + >(options, features, exceptionRouterDict), }); return { i18n, + features, }; } diff --git a/src/initialize.prod.mp.ts b/src/initialize.prod.mp.ts index 0647bff7..3f7a5c6c 100644 --- a/src/initialize.prod.mp.ts +++ b/src/initialize.prod.mp.ts @@ -33,19 +33,18 @@ export function initialize< createFeatures: ( aspectWrapper: AspectWrapper, basicFeatures: BasicFeatures>, - context: Cxt ) => FD, - contextBuilder: (cxtString?: string) => (store: RowStore) => Cxt, + frontendContextBuilder: (features: FD & BasicFeatures>) => (store: RowStore) => Cxt, exceptionRouters: ExceptionRouters = [], connector: Connector, checkers?: Array>, actionDict?: ActionDictOfEntityDict, i18nOptions?: I18nOptions ) { - const { features, context } = initProd( + const { features } = initProd( storageSchema, createFeatures, - contextBuilder, + frontendContextBuilder, connector, checkers, actionDict @@ -96,7 +95,7 @@ export function initialize< TData, TProperty, TMethod - >(options, features, exceptionRouterDict, context), + >(options, features, exceptionRouterDict), OakComponent: < T extends keyof ED, FormedData extends WechatMiniprogram.Component.DataOption, @@ -129,10 +128,11 @@ export function initialize< TData, TProperty, TMethod - >(options, features, exceptionRouterDict, context), + >(options, features, exceptionRouterDict), }); return { i18n, + features, }; } diff --git a/src/initialize.prod.web.ts b/src/initialize.prod.web.ts index b7e9f816..c7f3559b 100644 --- a/src/initialize.prod.web.ts +++ b/src/initialize.prod.web.ts @@ -33,19 +33,18 @@ export function initialize< createFeatures: ( aspectWrapper: AspectWrapper, basicFeatures: BasicFeatures>, - context: Cxt ) => FD, - contextBuilder: (cxtString?: string) => (store: RowStore) => Cxt, + frontendContextBuilder: (features: FD & BasicFeatures>) => (store: RowStore) => Cxt, exceptionRouters: ExceptionRouters = [], connector: Connector, checkers?: Array>, actionDict?: ActionDictOfEntityDict, i18nOptions?: I18nOptions ) { - const { features, context } = initProd( + const { features } = initProd( storageSchema, createFeatures, - contextBuilder, + frontendContextBuilder, connector, checkers, actionDict @@ -97,7 +96,7 @@ export function initialize< TData, TProperty, TMethod - >(options, features, exceptionRouterDict, context), + >(options, features, exceptionRouterDict), OakComponent: < T extends keyof ED, FormedData extends WechatMiniprogram.Component.DataOption, @@ -130,10 +129,11 @@ export function initialize< TData, TProperty, TMethod - >(options, features, exceptionRouterDict, context), + >(options, features, exceptionRouterDict), }); return { i18n, + features, }; } diff --git a/src/page.common.ts b/src/page.common.ts index 0e2a3d53..261ae25a 100644 --- a/src/page.common.ts +++ b/src/page.common.ts @@ -667,8 +667,7 @@ export function makePageMethods< TData, TProperty, TMethod - >, - context: Cxt, + > ): OakPageMethods & ComponentThisType { return { @@ -829,7 +828,6 @@ export function makePageMethods< : options.actions || [], }, async () => { - context.setScene(path2); this.refresh(); options.methods?.onLoad && (await options.methods.onLoad.call( diff --git a/src/page.mp.ts b/src/page.mp.ts index 26a67f2d..90342e2c 100644 --- a/src/page.mp.ts +++ b/src/page.mp.ts @@ -264,11 +264,10 @@ function makePageMethods< TData, TProperty, TMethod - >, - context: Cxt, + > ): OakPageMethods & ComponentThisType { - const { onPullDownRefresh, onLoad, ...rest } = makePage(features, options, context); + const { onPullDownRefresh, onLoad, ...rest } = makePage(features, options); return { async onPullDownRefresh() { await onPullDownRefresh.call(this); @@ -325,8 +324,7 @@ export function createPage< TMethod >, features: BasicFeatures> & FD, - exceptionRouterDict: Record, - context: Cxt + exceptionRouterDict: Record ) { const { formData, isList } = options; const hiddenMethods = makeHiddenComponentMethods(); @@ -337,7 +335,7 @@ export function createPage< ); const listMethods = makeListComponentMethods(features); const { onLoad, onPullDownRefresh, onReachBottom, ...restPageMethods } = - makePageMethods(features, options, context); + makePageMethods(features, options); const { methods, lifetimes, pageLifetimes } = options; return Component({ @@ -444,7 +442,6 @@ export function createPage< show() { this.subscribe(); if (this.data.oakFullpath) { - context.setScene(this.data.oakFullpath); this.reRender(); } pageLifetimes?.show && pageLifetimes.show.call(this); @@ -485,8 +482,7 @@ export function createComponent< TMethod >, features: BasicFeatures> & FD, - exceptionRouterDict: Record, - context: Cxt + exceptionRouterDict: Record ) { const { formData, diff --git a/src/page.web.tsx b/src/page.web.tsx index b7032f35..cc354c22 100644 --- a/src/page.web.tsx +++ b/src/page.web.tsx @@ -190,11 +190,10 @@ function makePageMethods< TData, TProperty, TMethod - >, - context: Cxt + > ): OakPageMethods & ComponentThisType { - const { onPullDownRefresh, ...rest } = makePage(features, options, context); + const { onPullDownRefresh, ...rest } = makePage(features, options); return { async onPullDownRefresh() { await onPullDownRefresh.call(this); @@ -285,8 +284,7 @@ export function createPage< TMethod >, features: BasicFeatures> & FD, - exceptionRouterDict: Record, - context: Cxt + exceptionRouterDict: Record ) { const { formData, isList, render } = options as OakPageOption< ED, @@ -320,7 +318,7 @@ export function createPage< ); const listMethods = makeListComponentMethods(features); const { onLoad, onPullDownRefresh, onReachBottom, ...restPageMethods } = - makePageMethods(features, options, context); + makePageMethods(features, options); const { methods, lifetimes, pageLifetimes, data, observers } = options; @@ -362,7 +360,6 @@ export function createPage< }); } } - context.setScene(options.path); lifetimes?.created && lifetimes.created.call(this); } @@ -494,7 +491,6 @@ export function createComponent< >, features: BasicFeatures> & FD, exceptionRouterDict: Record, - context: Cxt ) { const { formData,