context和feature之间的关系重构
This commit is contained in:
parent
4efe475c08
commit
6e0a817d13
|
|
@ -7,7 +7,7 @@ export declare class CacheStore<ED extends EntityDict & BaseEntityDict, Cxt exte
|
|||
private executor;
|
||||
private getFullDataFn?;
|
||||
private resetInitialDataFn?;
|
||||
constructor(storageSchema: StorageSchema<ED>, contextBuilder: (cxtString: string) => (store: CacheStore<ED, Cxt>) => Cxt, getFullDataFn?: () => any, resetInitialDataFn?: () => void);
|
||||
constructor(storageSchema: StorageSchema<ED>, contextBuilder: () => (store: CacheStore<ED, Cxt>) => Cxt, getFullDataFn?: () => any, resetInitialDataFn?: () => void);
|
||||
operate<T extends keyof ED, OP extends OperateOption>(entity: T, operation: ED[T]['Operation'], context: Cxt, option: OP): Promise<OperationResult<ED>>;
|
||||
sync(opRecords: Array<OpRecord<ED>>, context: Cxt): Promise<void>;
|
||||
select<T extends keyof ED, S extends ED[T]['Selection'], OP extends SelectOption>(entity: T, selection: S, context: Cxt, option: OP): Promise<import("oak-domain/lib/types").SelectionResult<ED[T]["Schema"], S["data"]>>;
|
||||
|
|
|
|||
|
|
@ -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];
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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<ED extends EntityDict & BaseEntityDict, Cxt extends Context<ED>> extends TreeStore<ED, Cxt> {
|
||||
private executor;
|
||||
private rwLock;
|
||||
constructor(storageSchema: StorageSchema<ED>, contextBuilder: (cxtString?: string) => (store: RowStore<ED, Cxt>) => Promise<Cxt>);
|
||||
protected cascadeUpdate<T extends keyof ED, OP extends DebugStoreOperateOption>(entity: T, operation: DeduceCreateOperation<ED[T]["Schema"]> | DeduceUpdateOperation<ED[T]["Schema"]> | DeduceRemoveOperation<ED[T]["Schema"]>, context: Cxt, option: OP): Promise<import("oak-domain/lib/types").OperationResult<ED>>;
|
||||
protected cascadeSelect<T extends keyof ED, S extends ED[T]["Selection"], OP extends DebugStoreSelectOption>(entity: T, selection: S, context: Cxt, option: OP): Promise<SelectRowShape<ED[T]['Schema'], S['data']>[]>;
|
||||
operate<T extends keyof ED, OP extends DebugStoreOperateOption>(entity: T, operation: ED[T]['Operation'], context: Cxt, option: OP): Promise<import("oak-domain/lib/types").OperationResult<ED>>;
|
||||
select<T extends keyof ED, S extends ED[T]['Selection'], OP extends DebugStoreSelectOption>(entity: T, selection: S, context: Cxt, option: OP): Promise<SelectionResult<ED[T]["Schema"], S["data"]>>;
|
||||
registerTrigger<T extends keyof ED>(trigger: Trigger<ED, T, Cxt>): void;
|
||||
registerChecker<T extends keyof ED>(checker: Checker<ED, T, Cxt>): void;
|
||||
startInitializing(): void;
|
||||
endInitializing(): void;
|
||||
}
|
||||
export {};
|
||||
|
|
@ -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;
|
||||
|
|
@ -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<ED extends EntityDict & BaseEntityDict, Cxt extends Context<ED>>(storageSchema: StorageSchema<ED>, contextBuilder: (cxtString?: string) => (store: RowStore<ED, Cxt>) => Cxt, triggers: Array<Trigger<ED, keyof ED, Cxt>>, checkers: Array<Checker<ED, keyof ED, Cxt>>, watchers: Array<Watcher<ED, keyof ED, Cxt>>, initialData?: {
|
||||
export declare function createDebugStore<ED extends EntityDict & BaseEntityDict, Cxt extends Context<ED>>(storageSchema: StorageSchema<ED>, contextBuilder: (cxtString?: string) => (store: RowStore<ED, Cxt>) => Promise<Cxt>, triggers: Array<Trigger<ED, keyof ED, Cxt>>, checkers: Array<Checker<ED, keyof ED, Cxt>>, watchers: Array<Watcher<ED, keyof ED, Cxt>>, initialData?: {
|
||||
[T in keyof ED]?: Array<ED[T]['OpSchema']>;
|
||||
}, actionDict?: ActionDictOfEntityDict<ED>): DebugStore<ED, Cxt>;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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<ED extends EntityDict & BaseEntityDict, Cxt extends Context<ED>, AD extends CommonAspectDict<ED, Cxt>> extends Feature<ED, Cxt, AD> {
|
||||
cacheStore: CacheStore<ED, Cxt>;
|
||||
context: Cxt;
|
||||
cacheStore?: CacheStore<ED, Cxt>;
|
||||
private syncEventsCallbacks;
|
||||
private contextBuilder;
|
||||
private contextBuilder?;
|
||||
private syncLock;
|
||||
constructor(aspectWrapper: AspectWrapper<ED, Cxt, AD>, context: Cxt, cacheStore: CacheStore<ED, Cxt>, contextBuilder: () => Cxt);
|
||||
constructor(aspectWrapper: AspectWrapper<ED, Cxt, AD>);
|
||||
/**
|
||||
* 目前context和cache会形成循环依赖,这里不太好处理,只能先让contextBuilder后注入
|
||||
* @param contextBuilder
|
||||
*/
|
||||
init(contextBuilder: () => Cxt, store: CacheStore<ED, Cxt>): void;
|
||||
refresh<T extends keyof ED, OP extends SelectOption>(entity: T, selection: ED[T]['Selection'], option?: OP, getCount?: true): Promise<{
|
||||
data: import("oak-domain/lib/types").SelectRowShape<ED[keyof ED]["Schema"], ED[keyof ED]["Selection"]["data"]>[];
|
||||
count?: number | undefined;
|
||||
|
|
@ -25,7 +29,7 @@ export declare class Cache<ED extends EntityDict & BaseEntityDict, Cxt extends C
|
|||
* @param option
|
||||
* @returns
|
||||
*/
|
||||
testOperation<T extends keyof ED>(entity: T, operation: ED[T]['Operation']): Promise<import("oak-domain/lib/types").OperationResult<ED>>;
|
||||
testOperation<T extends keyof ED>(entity: T, operation: ED[T]['Operation']): Promise<boolean>;
|
||||
/**
|
||||
* 尝试在cache中重做一些动作,然后选择重做后的数据(为了实现modi)
|
||||
* @param entity
|
||||
|
|
@ -35,7 +39,7 @@ export declare class Cache<ED extends EntityDict & BaseEntityDict, Cxt extends C
|
|||
tryRedoOperations<T extends keyof ED, S extends ED[T]['Selection']>(entity: T, selection: S, opers: Array<{
|
||||
entity: keyof ED;
|
||||
operation: ED[keyof ED]['Operation'];
|
||||
}>): Promise<import("oak-domain/lib/types").SelectionResult<ED[keyof ED]["Schema"], ED[keyof ED]["Selection"]["data"]>>;
|
||||
}>): Promise<SelectionResult<ED[T]["Schema"], S["data"]>>;
|
||||
get<T extends keyof ED, S extends ED[T]['Selection']>(entity: T, selection: S, params?: SelectOption): Promise<import("oak-domain/lib/types").SelectRowShape<ED[T]["Schema"], S["data"]>[]>;
|
||||
judgeRelation(entity: keyof ED, attr: string): string | 0 | 1 | string[] | 2;
|
||||
bindOnSync(callback: (opRecords: OpRecord<ED>[]) => Promise<void>): void;
|
||||
|
|
|
|||
|
|
@ -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];
|
||||
|
|
|
|||
|
|
@ -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<ED extends EntityDict & BaseEntityDict, Cxt extends Context<ED>, AD extends CommonAspectDict<ED, Cxt>>(aspectWrapper: AspectWrapper<ED, Cxt, AD>, storageSchema: StorageSchema<ED>, context: Cxt, cacheStore: CacheStore<ED, Cxt>, contextBuilder: () => Cxt): BasicFeatures<ED, Cxt, AD>;
|
||||
export declare function initialize<ED extends EntityDict & BaseEntityDict, Cxt extends Context<ED>, AD extends CommonAspectDict<ED, Cxt>>(aspectWrapper: AspectWrapper<ED, Cxt, AD>, storageSchema: StorageSchema<ED>): {
|
||||
cache: Cache<ED, Cxt, AD>;
|
||||
location: Location<ED, Cxt, AD>;
|
||||
runningTree: RunningTree<ED, Cxt, AD>;
|
||||
locales: Locales<ED, Cxt, AD>;
|
||||
eventBus: EventBus<ED, Cxt, AD>;
|
||||
localStorage: LocalStorage<ED, Cxt, AD>;
|
||||
notification: Notification<ED, Cxt, AD>;
|
||||
message: Message<ED, Cxt, AD>;
|
||||
};
|
||||
export declare type BasicFeatures<ED extends EntityDict & BaseEntityDict, Cxt extends Context<ED>, AD extends CommonAspectDict<ED, Cxt>> = {
|
||||
cache: Cache<ED, Cxt, AD>;
|
||||
location: Location<ED, Cxt, AD>;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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<ED extends EntityDict & BaseEntityDict, Cxt extends Context<ED>, AD extends Record<string, Aspect<ED, Cxt>>, FD extends Record<string, Feature<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>>>(storageSchema: StorageSchema<ED>, createFeatures: (aspectWrapper: AspectWrapper<ED, Cxt, AD>, basicFeatures: BasicFeatures<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>, context: Cxt) => FD, contextBuilder: (cxtString?: string) => (store: RowStore<ED, Cxt>) => Cxt, aspectDict: AD, triggers?: Array<Trigger<ED, keyof ED, Cxt>>, checkers?: Array<Checker<ED, keyof ED, Cxt>>, watchers?: Array<Watcher<ED, keyof ED, Cxt>>, initialData?: {
|
||||
export declare function initialize<ED extends EntityDict & BaseEntityDict, Cxt extends Context<ED>, AD extends Record<string, Aspect<ED, Cxt>>, FD extends Record<string, Feature<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>>>(storageSchema: StorageSchema<ED>, createFeatures: (aspectWrapper: AspectWrapper<ED, Cxt, AD>, basicFeatures: BasicFeatures<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>) => FD, frontendContextBuilder: (features: FD & BasicFeatures<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>) => (store: RowStore<ED, Cxt>) => Cxt, backendContextBuilder: (contextStr?: string) => (store: RowStore<ED, Cxt>) => Promise<Cxt>, aspectDict: AD, triggers?: Array<Trigger<ED, keyof ED, Cxt>>, checkers?: Array<Checker<ED, keyof ED, Cxt>>, watchers?: Array<Watcher<ED, keyof ED, Cxt>>, initialData?: {
|
||||
[T in keyof ED]?: Array<ED[T]['OpSchema']>;
|
||||
}, actionDict?: ActionDictOfEntityDict<ED>): {
|
||||
features: BasicFeatures<ED, Cxt, {
|
||||
operate: typeof import("oak-common-aspect/src/crud").operate;
|
||||
select: typeof import("oak-common-aspect/src/crud").select;
|
||||
fetchRows: typeof import("oak-common-aspect/src/crud").fetchRows;
|
||||
amap: typeof import("oak-common-aspect/src/amap").amap;
|
||||
getTranslations: typeof import("oak-common-aspect/src/locales").getTranslations;
|
||||
} & AD> & FD;
|
||||
context: Cxt;
|
||||
features: {
|
||||
cache: import(".").Cache<ED, Cxt, {
|
||||
operate: typeof import("oak-common-aspect/src/crud").operate;
|
||||
select: typeof import("oak-common-aspect/src/crud").select;
|
||||
fetchRows: typeof import("oak-common-aspect/src/crud").fetchRows;
|
||||
amap: typeof import("oak-common-aspect/src/amap").amap;
|
||||
getTranslations: typeof import("oak-common-aspect/src/locales").getTranslations;
|
||||
} & AD>;
|
||||
location: import("./features/location").Location<ED, Cxt, {
|
||||
operate: typeof import("oak-common-aspect/src/crud").operate;
|
||||
select: typeof import("oak-common-aspect/src/crud").select;
|
||||
fetchRows: typeof import("oak-common-aspect/src/crud").fetchRows;
|
||||
amap: typeof import("oak-common-aspect/src/amap").amap;
|
||||
getTranslations: typeof import("oak-common-aspect/src/locales").getTranslations;
|
||||
} & AD>;
|
||||
runningTree: import("./features/runningTree").RunningTree<ED, Cxt, {
|
||||
operate: typeof import("oak-common-aspect/src/crud").operate;
|
||||
select: typeof import("oak-common-aspect/src/crud").select;
|
||||
fetchRows: typeof import("oak-common-aspect/src/crud").fetchRows;
|
||||
amap: typeof import("oak-common-aspect/src/amap").amap;
|
||||
getTranslations: typeof import("oak-common-aspect/src/locales").getTranslations;
|
||||
} & AD>;
|
||||
locales: import("./features/locales").Locales<ED, Cxt, {
|
||||
operate: typeof import("oak-common-aspect/src/crud").operate;
|
||||
select: typeof import("oak-common-aspect/src/crud").select;
|
||||
fetchRows: typeof import("oak-common-aspect/src/crud").fetchRows;
|
||||
amap: typeof import("oak-common-aspect/src/amap").amap;
|
||||
getTranslations: typeof import("oak-common-aspect/src/locales").getTranslations;
|
||||
} & AD>;
|
||||
eventBus: import("./features/eventBus").EventBus<ED, Cxt, {
|
||||
operate: typeof import("oak-common-aspect/src/crud").operate;
|
||||
select: typeof import("oak-common-aspect/src/crud").select;
|
||||
fetchRows: typeof import("oak-common-aspect/src/crud").fetchRows;
|
||||
amap: typeof import("oak-common-aspect/src/amap").amap;
|
||||
getTranslations: typeof import("oak-common-aspect/src/locales").getTranslations;
|
||||
} & AD>;
|
||||
localStorage: import(".").LocalStorage<ED, Cxt, {
|
||||
operate: typeof import("oak-common-aspect/src/crud").operate;
|
||||
select: typeof import("oak-common-aspect/src/crud").select;
|
||||
fetchRows: typeof import("oak-common-aspect/src/crud").fetchRows;
|
||||
amap: typeof import("oak-common-aspect/src/amap").amap;
|
||||
getTranslations: typeof import("oak-common-aspect/src/locales").getTranslations;
|
||||
} & AD>;
|
||||
notification: import("./features/notification").Notification<ED, Cxt, {
|
||||
operate: typeof import("oak-common-aspect/src/crud").operate;
|
||||
select: typeof import("oak-common-aspect/src/crud").select;
|
||||
fetchRows: typeof import("oak-common-aspect/src/crud").fetchRows;
|
||||
amap: typeof import("oak-common-aspect/src/amap").amap;
|
||||
getTranslations: typeof import("oak-common-aspect/src/locales").getTranslations;
|
||||
} & AD>;
|
||||
message: import("./features/message").Message<ED, Cxt, {
|
||||
operate: typeof import("oak-common-aspect/src/crud").operate;
|
||||
select: typeof import("oak-common-aspect/src/crud").select;
|
||||
fetchRows: typeof import("oak-common-aspect/src/crud").fetchRows;
|
||||
amap: typeof import("oak-common-aspect/src/amap").amap;
|
||||
getTranslations: typeof import("oak-common-aspect/src/locales").getTranslations;
|
||||
} & AD>;
|
||||
} & FD;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -18,7 +18,15 @@ import { CommonAspectDict } from 'oak-common-aspect';
|
|||
* @param actionDict
|
||||
* @returns
|
||||
*/
|
||||
export declare function initialize<ED extends EntityDict & BaseEntityDict, Cxt extends Context<ED>, AD extends Record<string, Aspect<ED, Cxt>>, FD extends Record<string, Feature<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>>>(storageSchema: StorageSchema<ED>, createFeatures: (aspectWrapper: AspectWrapper<ED, Cxt, AD>, basicFeatures: BasicFeatures<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>, context: Cxt) => FD, contextBuilder: (cxtString?: string) => (store: RowStore<ED, Cxt>) => Cxt, connector: Connector<ED, Cxt>, checkers?: Array<Checker<ED, keyof ED, Cxt>>, actionDict?: ActionDictOfEntityDict<ED>): {
|
||||
features: BasicFeatures<ED, Cxt, AD & CommonAspectDict<ED, Cxt>> & FD;
|
||||
context: Cxt;
|
||||
export declare function initialize<ED extends EntityDict & BaseEntityDict, Cxt extends Context<ED>, AD extends Record<string, Aspect<ED, Cxt>>, FD extends Record<string, Feature<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>>>(storageSchema: StorageSchema<ED>, createFeatures: (aspectWrapper: AspectWrapper<ED, Cxt, AD>, basicFeatures: BasicFeatures<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>) => FD, frontendContextBuilder: (features: FD & BasicFeatures<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>) => (store: RowStore<ED, Cxt>) => Cxt, connector: Connector<ED, Cxt>, checkers?: Array<Checker<ED, keyof ED, Cxt>>, actionDict?: ActionDictOfEntityDict<ED>): {
|
||||
features: {
|
||||
cache: import(".").Cache<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>;
|
||||
location: import("./features/location").Location<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>;
|
||||
runningTree: import("./features/runningTree").RunningTree<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>;
|
||||
locales: import("./features/locales").Locales<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>;
|
||||
eventBus: import("./features/eventBus").EventBus<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>;
|
||||
localStorage: import(".").LocalStorage<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>;
|
||||
notification: import("./features/notification").Notification<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>;
|
||||
message: import("./features/message").Message<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>;
|
||||
} & FD;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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<ED extends EntityDict & BaseEntityDict, Cxt extends Context<ED>, AD extends Record<string, Aspect<ED, Cxt>>, FD extends Record<string, Feature<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>>>(storageSchema: StorageSchema<ED>, createFeatures: (aspectWrapper: AspectWrapper<ED, Cxt, AD>, basicFeatures: BasicFeatures<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>, context: Cxt) => FD, contextBuilder: (cxtString?: string) => (store: RowStore<ED, Cxt>) => Cxt, aspectDict: AD, exceptionRouters?: ExceptionRouters, triggers?: Array<Trigger<ED, keyof ED, Cxt>>, checkers?: Array<Checker<ED, keyof ED, Cxt>>, watchers?: Array<Watcher<ED, keyof ED, Cxt>>, initialData?: {
|
||||
export declare function initialize<ED extends EntityDict & BaseEntityDict, Cxt extends Context<ED>, AD extends Record<string, Aspect<ED, Cxt>>, FD extends Record<string, Feature<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>>>(storageSchema: StorageSchema<ED>, createFeatures: (aspectWrapper: AspectWrapper<ED, Cxt, AD>, basicFeatures: BasicFeatures<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>) => FD, frontendContextBuilder: (features: FD & BasicFeatures<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>) => (store: RowStore<ED, Cxt>) => Cxt, backendContextBuilder: (contextStr?: string) => (store: RowStore<ED, Cxt>) => Promise<Cxt>, aspectDict: AD, exceptionRouters?: ExceptionRouters, triggers?: Array<Trigger<ED, keyof ED, Cxt>>, checkers?: Array<Checker<ED, keyof ED, Cxt>>, watchers?: Array<Watcher<ED, keyof ED, Cxt>>, initialData?: {
|
||||
[T in keyof ED]?: Array<ED[T]['OpSchema']>;
|
||||
}, actionDict?: ActionDictOfEntityDict<ED>, i18nOptions?: I18nOptions): {
|
||||
i18n: import("./platforms/wechatMp/i18n").I18nWechatMpRuntimeBase;
|
||||
features: {
|
||||
cache: import(".").Cache<ED, Cxt, {
|
||||
operate: typeof import("oak-common-aspect/src/crud").operate;
|
||||
select: typeof import("oak-common-aspect/src/crud").select;
|
||||
fetchRows: typeof import("oak-common-aspect/src/crud").fetchRows;
|
||||
amap: typeof import("oak-common-aspect/src/amap").amap;
|
||||
getTranslations: typeof import("oak-common-aspect/src/locales").getTranslations;
|
||||
} & AD>;
|
||||
location: import("./features/location").Location<ED, Cxt, {
|
||||
operate: typeof import("oak-common-aspect/src/crud").operate;
|
||||
select: typeof import("oak-common-aspect/src/crud").select;
|
||||
fetchRows: typeof import("oak-common-aspect/src/crud").fetchRows;
|
||||
amap: typeof import("oak-common-aspect/src/amap").amap;
|
||||
getTranslations: typeof import("oak-common-aspect/src/locales").getTranslations;
|
||||
} & AD>;
|
||||
runningTree: import("./features/runningTree").RunningTree<ED, Cxt, {
|
||||
operate: typeof import("oak-common-aspect/src/crud").operate;
|
||||
select: typeof import("oak-common-aspect/src/crud").select;
|
||||
fetchRows: typeof import("oak-common-aspect/src/crud").fetchRows;
|
||||
amap: typeof import("oak-common-aspect/src/amap").amap;
|
||||
getTranslations: typeof import("oak-common-aspect/src/locales").getTranslations;
|
||||
} & AD>;
|
||||
locales: import("./features/locales").Locales<ED, Cxt, {
|
||||
operate: typeof import("oak-common-aspect/src/crud").operate;
|
||||
select: typeof import("oak-common-aspect/src/crud").select;
|
||||
fetchRows: typeof import("oak-common-aspect/src/crud").fetchRows;
|
||||
amap: typeof import("oak-common-aspect/src/amap").amap;
|
||||
getTranslations: typeof import("oak-common-aspect/src/locales").getTranslations;
|
||||
} & AD>;
|
||||
eventBus: import("./features/eventBus").EventBus<ED, Cxt, {
|
||||
operate: typeof import("oak-common-aspect/src/crud").operate;
|
||||
select: typeof import("oak-common-aspect/src/crud").select;
|
||||
fetchRows: typeof import("oak-common-aspect/src/crud").fetchRows;
|
||||
amap: typeof import("oak-common-aspect/src/amap").amap;
|
||||
getTranslations: typeof import("oak-common-aspect/src/locales").getTranslations;
|
||||
} & AD>;
|
||||
localStorage: import(".").LocalStorage<ED, Cxt, {
|
||||
operate: typeof import("oak-common-aspect/src/crud").operate;
|
||||
select: typeof import("oak-common-aspect/src/crud").select;
|
||||
fetchRows: typeof import("oak-common-aspect/src/crud").fetchRows;
|
||||
amap: typeof import("oak-common-aspect/src/amap").amap;
|
||||
getTranslations: typeof import("oak-common-aspect/src/locales").getTranslations;
|
||||
} & AD>;
|
||||
notification: import("./features/notification").Notification<ED, Cxt, {
|
||||
operate: typeof import("oak-common-aspect/src/crud").operate;
|
||||
select: typeof import("oak-common-aspect/src/crud").select;
|
||||
fetchRows: typeof import("oak-common-aspect/src/crud").fetchRows;
|
||||
amap: typeof import("oak-common-aspect/src/amap").amap;
|
||||
getTranslations: typeof import("oak-common-aspect/src/locales").getTranslations;
|
||||
} & AD>;
|
||||
message: import("./features/message").Message<ED, Cxt, {
|
||||
operate: typeof import("oak-common-aspect/src/crud").operate;
|
||||
select: typeof import("oak-common-aspect/src/crud").select;
|
||||
fetchRows: typeof import("oak-common-aspect/src/crud").fetchRows;
|
||||
amap: typeof import("oak-common-aspect/src/amap").amap;
|
||||
getTranslations: typeof import("oak-common-aspect/src/locales").getTranslations;
|
||||
} & AD>;
|
||||
} & FD;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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<ED extends EntityDict & BaseEntityDict, Cxt extends Context<ED>, AD extends Record<string, Aspect<ED, Cxt>>, FD extends Record<string, Feature<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>>>(storageSchema: StorageSchema<ED>, createFeatures: (aspectWrapper: AspectWrapper<ED, Cxt, AD>, basicFeatures: BasicFeatures<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>, context: Cxt) => FD, contextBuilder: (cxtString?: string) => (store: RowStore<ED, Cxt>) => Cxt, aspectDict: AD, exceptionRouters?: ExceptionRouters, triggers?: Array<Trigger<ED, keyof ED, Cxt>>, checkers?: Array<Checker<ED, keyof ED, Cxt>>, watchers?: Array<Watcher<ED, keyof ED, Cxt>>, initialData?: {
|
||||
export declare function initialize<ED extends EntityDict & BaseEntityDict, Cxt extends Context<ED>, AD extends Record<string, Aspect<ED, Cxt>>, FD extends Record<string, Feature<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>>>(storageSchema: StorageSchema<ED>, createFeatures: (aspectWrapper: AspectWrapper<ED, Cxt, AD>, basicFeatures: BasicFeatures<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>) => FD, frontendContextBuilder: (features: FD & BasicFeatures<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>) => (store: RowStore<ED, Cxt>) => Cxt, backendContextBuilder: (contextStr?: string) => (store: RowStore<ED, Cxt>) => Promise<Cxt>, aspectDict: AD, exceptionRouters?: ExceptionRouters, triggers?: Array<Trigger<ED, keyof ED, Cxt>>, checkers?: Array<Checker<ED, keyof ED, Cxt>>, watchers?: Array<Watcher<ED, keyof ED, Cxt>>, initialData?: {
|
||||
[T in keyof ED]?: Array<ED[T]['OpSchema']>;
|
||||
}, actionDict?: ActionDictOfEntityDict<ED>, i18nOptions?: I18nOptions): {
|
||||
i18n: import("i18next").i18n;
|
||||
features: {
|
||||
cache: import(".").Cache<ED, Cxt, {
|
||||
operate: typeof import("oak-common-aspect/src/crud").operate;
|
||||
select: typeof import("oak-common-aspect/src/crud").select;
|
||||
fetchRows: typeof import("oak-common-aspect/src/crud").fetchRows;
|
||||
amap: typeof import("oak-common-aspect/src/amap").amap;
|
||||
getTranslations: typeof import("oak-common-aspect/src/locales").getTranslations;
|
||||
} & AD>;
|
||||
location: import("./features/location").Location<ED, Cxt, {
|
||||
operate: typeof import("oak-common-aspect/src/crud").operate;
|
||||
select: typeof import("oak-common-aspect/src/crud").select;
|
||||
fetchRows: typeof import("oak-common-aspect/src/crud").fetchRows;
|
||||
amap: typeof import("oak-common-aspect/src/amap").amap;
|
||||
getTranslations: typeof import("oak-common-aspect/src/locales").getTranslations;
|
||||
} & AD>;
|
||||
runningTree: import("./features/runningTree").RunningTree<ED, Cxt, {
|
||||
operate: typeof import("oak-common-aspect/src/crud").operate;
|
||||
select: typeof import("oak-common-aspect/src/crud").select;
|
||||
fetchRows: typeof import("oak-common-aspect/src/crud").fetchRows;
|
||||
amap: typeof import("oak-common-aspect/src/amap").amap;
|
||||
getTranslations: typeof import("oak-common-aspect/src/locales").getTranslations;
|
||||
} & AD>;
|
||||
locales: import("./features/locales").Locales<ED, Cxt, {
|
||||
operate: typeof import("oak-common-aspect/src/crud").operate;
|
||||
select: typeof import("oak-common-aspect/src/crud").select;
|
||||
fetchRows: typeof import("oak-common-aspect/src/crud").fetchRows;
|
||||
amap: typeof import("oak-common-aspect/src/amap").amap;
|
||||
getTranslations: typeof import("oak-common-aspect/src/locales").getTranslations;
|
||||
} & AD>;
|
||||
eventBus: import("./features/eventBus").EventBus<ED, Cxt, {
|
||||
operate: typeof import("oak-common-aspect/src/crud").operate;
|
||||
select: typeof import("oak-common-aspect/src/crud").select;
|
||||
fetchRows: typeof import("oak-common-aspect/src/crud").fetchRows;
|
||||
amap: typeof import("oak-common-aspect/src/amap").amap;
|
||||
getTranslations: typeof import("oak-common-aspect/src/locales").getTranslations;
|
||||
} & AD>;
|
||||
localStorage: import(".").LocalStorage<ED, Cxt, {
|
||||
operate: typeof import("oak-common-aspect/src/crud").operate;
|
||||
select: typeof import("oak-common-aspect/src/crud").select;
|
||||
fetchRows: typeof import("oak-common-aspect/src/crud").fetchRows;
|
||||
amap: typeof import("oak-common-aspect/src/amap").amap;
|
||||
getTranslations: typeof import("oak-common-aspect/src/locales").getTranslations;
|
||||
} & AD>;
|
||||
notification: import("./features/notification").Notification<ED, Cxt, {
|
||||
operate: typeof import("oak-common-aspect/src/crud").operate;
|
||||
select: typeof import("oak-common-aspect/src/crud").select;
|
||||
fetchRows: typeof import("oak-common-aspect/src/crud").fetchRows;
|
||||
amap: typeof import("oak-common-aspect/src/amap").amap;
|
||||
getTranslations: typeof import("oak-common-aspect/src/locales").getTranslations;
|
||||
} & AD>;
|
||||
message: import("./features/message").Message<ED, Cxt, {
|
||||
operate: typeof import("oak-common-aspect/src/crud").operate;
|
||||
select: typeof import("oak-common-aspect/src/crud").select;
|
||||
fetchRows: typeof import("oak-common-aspect/src/crud").fetchRows;
|
||||
amap: typeof import("oak-common-aspect/src/amap").amap;
|
||||
getTranslations: typeof import("oak-common-aspect/src/locales").getTranslations;
|
||||
} & AD>;
|
||||
} & FD;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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<ED extends EntityDict & BaseEntityDict, Cxt extends Context<ED>, AD extends Record<string, Aspect<ED, Cxt>>, FD extends Record<string, Feature<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>>>(storageSchema: StorageSchema<ED>, createFeatures: (aspectWrapper: AspectWrapper<ED, Cxt, AD>, basicFeatures: BasicFeatures<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>, context: Cxt) => FD, contextBuilder: (cxtString?: string) => (store: RowStore<ED, Cxt>) => Cxt, exceptionRouters: ExceptionRouters | undefined, connector: Connector<ED, Cxt>, checkers?: Array<Checker<ED, keyof ED, Cxt>>, actionDict?: ActionDictOfEntityDict<ED>, i18nOptions?: I18nOptions): {
|
||||
export declare function initialize<ED extends EntityDict & BaseEntityDict, Cxt extends Context<ED>, AD extends Record<string, Aspect<ED, Cxt>>, FD extends Record<string, Feature<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>>>(storageSchema: StorageSchema<ED>, createFeatures: (aspectWrapper: AspectWrapper<ED, Cxt, AD>, basicFeatures: BasicFeatures<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>) => FD, frontendContextBuilder: (features: FD & BasicFeatures<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>) => (store: RowStore<ED, Cxt>) => Cxt, exceptionRouters: ExceptionRouters | undefined, connector: Connector<ED, Cxt>, checkers?: Array<Checker<ED, keyof ED, Cxt>>, actionDict?: ActionDictOfEntityDict<ED>, i18nOptions?: I18nOptions): {
|
||||
i18n: import("./platforms/wechatMp/i18n").I18nWechatMpRuntimeBase;
|
||||
features: {
|
||||
cache: import(".").Cache<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>;
|
||||
location: import("./features/location").Location<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>;
|
||||
runningTree: import("./features/runningTree").RunningTree<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>;
|
||||
locales: import("./features/locales").Locales<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>;
|
||||
eventBus: import("./features/eventBus").EventBus<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>;
|
||||
localStorage: import(".").LocalStorage<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>;
|
||||
notification: import("./features/notification").Notification<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>;
|
||||
message: import("./features/message").Message<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>;
|
||||
} & FD;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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<ED extends EntityDict & BaseEntityDict, Cxt extends Context<ED>, AD extends Record<string, Aspect<ED, Cxt>>, FD extends Record<string, Feature<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>>>(storageSchema: StorageSchema<ED>, createFeatures: (aspectWrapper: AspectWrapper<ED, Cxt, AD>, basicFeatures: BasicFeatures<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>, context: Cxt) => FD, contextBuilder: (cxtString?: string) => (store: RowStore<ED, Cxt>) => Cxt, exceptionRouters: ExceptionRouters | undefined, connector: Connector<ED, Cxt>, checkers?: Array<Checker<ED, keyof ED, Cxt>>, actionDict?: ActionDictOfEntityDict<ED>, i18nOptions?: I18nOptions): {
|
||||
export declare function initialize<ED extends EntityDict & BaseEntityDict, Cxt extends Context<ED>, AD extends Record<string, Aspect<ED, Cxt>>, FD extends Record<string, Feature<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>>>(storageSchema: StorageSchema<ED>, createFeatures: (aspectWrapper: AspectWrapper<ED, Cxt, AD>, basicFeatures: BasicFeatures<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>) => FD, frontendContextBuilder: (features: FD & BasicFeatures<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>) => (store: RowStore<ED, Cxt>) => Cxt, exceptionRouters: ExceptionRouters | undefined, connector: Connector<ED, Cxt>, checkers?: Array<Checker<ED, keyof ED, Cxt>>, actionDict?: ActionDictOfEntityDict<ED>, i18nOptions?: I18nOptions): {
|
||||
i18n: import("i18next").i18n;
|
||||
features: {
|
||||
cache: import(".").Cache<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>;
|
||||
location: import("./features/location").Location<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>;
|
||||
runningTree: import("./features/runningTree").RunningTree<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>;
|
||||
locales: import("./features/locales").Locales<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>;
|
||||
eventBus: import("./features/eventBus").EventBus<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>;
|
||||
localStorage: import(".").LocalStorage<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>;
|
||||
notification: import("./features/notification").Notification<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>;
|
||||
message: import("./features/message").Message<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>;
|
||||
} & FD;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -17,4 +17,4 @@ export declare type ComponentThisType<ED extends EntityDict & BaseEntityDict, T
|
|||
export declare function makeHiddenComponentMethods<ED extends EntityDict & BaseEntityDict, T extends keyof ED, FormedData extends WechatMiniprogram.Component.DataOption, IsList extends boolean, TData extends WechatMiniprogram.Component.DataOption, TProperty extends WechatMiniprogram.Component.PropertyOption, TMethod extends WechatMiniprogram.Component.MethodOption>(): OakHiddenComponentMethods & ComponentThisType<ED, T, FormedData, IsList, TData, TProperty, TMethod>;
|
||||
export declare function makeCommonComponentMethods<ED extends EntityDict & BaseEntityDict, T extends keyof ED, Cxt extends Context<ED>, AD extends Record<string, Aspect<ED, Cxt>>, FD extends Record<string, Feature<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>>, 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<ED, Cxt, AD & CommonAspectDict<ED, Cxt>> & FD, exceptionRouterDict: Record<string, ExceptionHandler>, formData: OakPageOption<ED, T, Cxt, AD, FD, Proj, FormedData, IsList, TData, TProperty, TMethod>['formData']): Omit<OakCommonComponentMethods<ED, T>, 'navigateTo' | 'navigateBack' | 'resolveInput' | 'redirectTo' | 't'> & ComponentThisType<ED, T, FormedData, IsList, TData, TProperty, TMethod>;
|
||||
export declare function makeListComponentMethods<ED extends EntityDict & BaseEntityDict, T extends keyof ED, Cxt extends Context<ED>, AD extends Record<string, Aspect<ED, Cxt>>, FD extends Record<string, Feature<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>>, 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<ED, Cxt, AD & CommonAspectDict<ED, Cxt>> & FD): OakListComponentMethods<ED, T> & ComponentThisType<ED, T, FormedData, IsList, TData, TProperty, TMethod>;
|
||||
export declare function makePageMethods<ED extends EntityDict & BaseEntityDict, T extends keyof ED, Cxt extends Context<ED>, AD extends Record<string, Aspect<ED, Cxt>>, FD extends Record<string, Feature<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>>, 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<ED, Cxt, AD & CommonAspectDict<ED, Cxt>> & FD, options: OakPageOption<ED, T, Cxt, AD, FD, Proj, FormedData, IsList, TData, TProperty, TMethod>, context: Cxt): OakPageMethods & ComponentThisType<ED, T, FormedData, IsList, TData, TProperty, TMethod>;
|
||||
export declare function makePageMethods<ED extends EntityDict & BaseEntityDict, T extends keyof ED, Cxt extends Context<ED>, AD extends Record<string, Aspect<ED, Cxt>>, FD extends Record<string, Feature<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>>, 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<ED, Cxt, AD & CommonAspectDict<ED, Cxt>> & FD, options: OakPageOption<ED, T, Cxt, AD, FD, Proj, FormedData, IsList, TData, TProperty, TMethod>): OakPageMethods & ComponentThisType<ED, T, FormedData, IsList, TData, TProperty, TMethod>;
|
||||
|
|
|
|||
|
|
@ -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];
|
||||
|
|
|
|||
|
|
@ -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<ED extends EntityDict & BaseEntityDict, T extends keyof ED, Cxt extends Context<ED>, AD extends Record<string, Aspect<ED, Cxt>>, FD extends Record<string, Feature<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>>, 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<ED, T, Cxt, AD, FD, Proj, FormedData, IsList, TData, TProperty, TMethod>, features: BasicFeatures<ED, Cxt, AD & CommonAspectDict<ED, Cxt>> & FD, exceptionRouterDict: Record<string, ExceptionHandler>, context: Cxt): string;
|
||||
export declare function createComponent<ED extends EntityDict & BaseEntityDict, T extends keyof ED, Cxt extends Context<ED>, AD extends Record<string, Aspect<ED, Cxt>>, FD extends Record<string, Feature<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>>, 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<ED, T, Cxt, AD, FD, FormedData, IsList, TData, TProperty, TMethod>, features: BasicFeatures<ED, Cxt, AD & CommonAspectDict<ED, Cxt>> & FD, exceptionRouterDict: Record<string, ExceptionHandler>, context: Cxt): string;
|
||||
export declare function createPage<ED extends EntityDict & BaseEntityDict, T extends keyof ED, Cxt extends Context<ED>, AD extends Record<string, Aspect<ED, Cxt>>, FD extends Record<string, Feature<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>>, 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<ED, T, Cxt, AD, FD, Proj, FormedData, IsList, TData, TProperty, TMethod>, features: BasicFeatures<ED, Cxt, AD & CommonAspectDict<ED, Cxt>> & FD, exceptionRouterDict: Record<string, ExceptionHandler>): string;
|
||||
export declare function createComponent<ED extends EntityDict & BaseEntityDict, T extends keyof ED, Cxt extends Context<ED>, AD extends Record<string, Aspect<ED, Cxt>>, FD extends Record<string, Feature<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>>, 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<ED, T, Cxt, AD, FD, FormedData, IsList, TData, TProperty, TMethod>, features: BasicFeatures<ED, Cxt, AD & CommonAspectDict<ED, Cxt>> & FD, exceptionRouterDict: Record<string, ExceptionHandler>): string;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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<ED extends EntityDict & BaseEntityDict, T extends keyof ED, Cxt extends Context<ED>, AD extends Record<string, Aspect<ED, Cxt>>, FD extends Record<string, Feature<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>>, 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<ED, T, Cxt, AD, FD, Proj, FormedData, IsList, TData, TProperty, TMethod>, features: BasicFeatures<ED, Cxt, AD & CommonAspectDict<ED, Cxt>> & FD, exceptionRouterDict: Record<string, ExceptionHandler>, context: Cxt): React.ForwardRefExoticComponent<React.RefAttributes<unknown>>;
|
||||
export declare function createComponent<ED extends EntityDict & BaseEntityDict, T extends keyof ED, Cxt extends Context<ED>, AD extends Record<string, Aspect<ED, Cxt>>, FD extends Record<string, Feature<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>>, 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<ED, T, Cxt, AD, FD, FormedData, IsList, TData, TProperty, TMethod>, features: BasicFeatures<ED, Cxt, AD & CommonAspectDict<ED, Cxt>> & FD, exceptionRouterDict: Record<string, ExceptionHandler>, context: Cxt): React.ForwardRefExoticComponent<React.RefAttributes<unknown>>;
|
||||
export declare function createPage<ED extends EntityDict & BaseEntityDict, T extends keyof ED, Cxt extends Context<ED>, AD extends Record<string, Aspect<ED, Cxt>>, FD extends Record<string, Feature<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>>, 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<ED, T, Cxt, AD, FD, Proj, FormedData, IsList, TData, TProperty, TMethod>, features: BasicFeatures<ED, Cxt, AD & CommonAspectDict<ED, Cxt>> & FD, exceptionRouterDict: Record<string, ExceptionHandler>): React.ForwardRefExoticComponent<React.RefAttributes<unknown>>;
|
||||
export declare function createComponent<ED extends EntityDict & BaseEntityDict, T extends keyof ED, Cxt extends Context<ED>, AD extends Record<string, Aspect<ED, Cxt>>, FD extends Record<string, Feature<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>>, 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<ED, T, Cxt, AD, FD, FormedData, IsList, TData, TProperty, TMethod>, features: BasicFeatures<ED, Cxt, AD & CommonAspectDict<ED, Cxt>> & FD, exceptionRouterDict: Record<string, ExceptionHandler>): React.ForwardRefExoticComponent<React.RefAttributes<unknown>>;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,15 +15,13 @@ export class CacheStore<
|
|||
|
||||
constructor(
|
||||
storageSchema: StorageSchema<ED>,
|
||||
contextBuilder: (
|
||||
cxtString: string
|
||||
) => (store: CacheStore<ED, Cxt>) => Cxt,
|
||||
contextBuilder: () => (store: CacheStore<ED, Cxt>) => 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;
|
||||
|
|
|
|||
|
|
@ -16,9 +16,9 @@ interface DebugStoreSelectOption extends SelectOption {
|
|||
export class DebugStore<ED extends EntityDict & BaseEntityDict, Cxt extends Context<ED>> extends TreeStore<ED, Cxt> {
|
||||
private executor: TriggerExecutor<ED, Cxt>;
|
||||
private rwLock: RWLock;
|
||||
constructor(storageSchema: StorageSchema<ED>, contextBuilder: (cxtString?: string) => (store: RowStore<ED, Cxt>) => Cxt) {
|
||||
constructor(storageSchema: StorageSchema<ED>, contextBuilder: (cxtString?: string) => (store: RowStore<ED, Cxt>) => Promise<Cxt>) {
|
||||
super(storageSchema);
|
||||
this.executor = new TriggerExecutor(async (cxtString) => contextBuilder(cxtString)(this));
|
||||
this.executor = new TriggerExecutor((cxtString) => contextBuilder(cxtString)(this));
|
||||
this.rwLock = new RWLock();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<ED extends EntityDict & BaseEntityDict, Cxt extends Context<ED>>(
|
||||
store: DebugStore<ED, Cxt>, contextBuilder: (cxtString?: string) => (store: RowStore<ED, Cxt>) => Cxt, watchers: Array<Watcher<ED, keyof ED, Cxt>>) {
|
||||
store: DebugStore<ED, Cxt>, contextBuilder: (cxtString?: string) => (store: RowStore<ED, Cxt>) => Promise<Cxt>, watchers: Array<Watcher<ED, keyof ED, Cxt>>) {
|
||||
|
||||
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<ED extends EntityDict & BaseEntityDict, Cxt extends
|
|||
|
||||
export function createDebugStore<ED extends EntityDict & BaseEntityDict, Cxt extends Context<ED>>(
|
||||
storageSchema: StorageSchema<ED>,
|
||||
contextBuilder: (cxtString?: string) => (store: RowStore<ED, Cxt>) => Cxt,
|
||||
contextBuilder: (cxtString?: string) => (store: RowStore<ED, Cxt>) => Promise<Cxt>,
|
||||
triggers: Array<Trigger<ED, keyof ED, Cxt>>,
|
||||
checkers: Array<Checker<ED, keyof ED, Cxt>>,
|
||||
watchers: Array<Watcher<ED, keyof ED, Cxt>>,
|
||||
|
|
|
|||
|
|
@ -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<ED>,
|
||||
AD extends CommonAspectDict<ED, Cxt>
|
||||
> extends Feature<ED, Cxt, AD> {
|
||||
cacheStore: CacheStore<ED, Cxt>;
|
||||
context: Cxt;
|
||||
cacheStore?: CacheStore<ED, Cxt>;
|
||||
private syncEventsCallbacks: Array<
|
||||
(opRecords: OpRecord<ED>[]) => Promise<void>
|
||||
>;
|
||||
private contextBuilder: () => Cxt;
|
||||
private contextBuilder?: () => Cxt;
|
||||
private syncLock: RWLock;
|
||||
|
||||
constructor(
|
||||
aspectWrapper: AspectWrapper<ED, Cxt, AD>,
|
||||
context: Cxt,
|
||||
cacheStore: CacheStore<ED, Cxt>,
|
||||
contextBuilder: () => Cxt
|
||||
) {
|
||||
constructor(aspectWrapper: AspectWrapper<ED, Cxt, AD>) {
|
||||
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<ED, Cxt>) {
|
||||
this.contextBuilder = contextBuilder;
|
||||
this.cacheStore = store;
|
||||
}
|
||||
|
||||
@Action
|
||||
async refresh<T extends keyof ED, OP extends SelectOption>(
|
||||
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<ED>[]) {
|
||||
// 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<ReturnType<typeof this.cacheStore.operate>>;
|
||||
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<ReturnType<typeof this.cacheStore.select>>;
|
||||
await this.context.begin();
|
||||
let result: SelectionResult<ED[T]['Schema'], S['data']>;
|
||||
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<ED>[]) => Promise<void>) {
|
||||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<ED extends EntityDict & BaseEntityDict, Cxt extends Context<ED>, AD extends CommonAspectDict<ED, Cxt>> (
|
||||
aspectWrapper: AspectWrapper<ED, Cxt, AD>,
|
||||
storageSchema: StorageSchema<ED>,
|
||||
context: Cxt,
|
||||
cacheStore: CacheStore<ED, Cxt>,
|
||||
contextBuilder: () => Cxt): BasicFeatures<ED, Cxt, AD> {
|
||||
const cache = new Cache<ED, Cxt, AD>(aspectWrapper, context, cacheStore, contextBuilder);
|
||||
storageSchema: StorageSchema<ED>) {
|
||||
const cache = new Cache<ED, Cxt, AD>(aspectWrapper);
|
||||
const location = new Location(aspectWrapper);
|
||||
const runningTree = new RunningTree<ED, Cxt, AD>(aspectWrapper, cache, storageSchema);
|
||||
const locales = new Locales(aspectWrapper);
|
||||
|
|
|
|||
|
|
@ -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<ED, Cxt, AD>,
|
||||
basicFeatures: BasicFeatures<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>,
|
||||
context: Cxt
|
||||
) => FD,
|
||||
contextBuilder: (cxtString?: string) => (store: RowStore<ED, Cxt>) => Cxt,
|
||||
frontendContextBuilder: (features: FD & BasicFeatures<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>) => (store: RowStore<ED, Cxt>) => Cxt,
|
||||
backendContextBuilder: (contextStr?: string) => (store: RowStore<ED, Cxt>) => Promise<Cxt>,
|
||||
aspectDict: AD,
|
||||
triggers?: Array<Trigger<ED, keyof ED, Cxt>>,
|
||||
checkers?: Array<Checker<ED, keyof ED, Cxt>>,
|
||||
|
|
@ -61,10 +60,10 @@ export function initialize<
|
|||
},
|
||||
actionDict?: ActionDictOfEntityDict<ED>
|
||||
) {
|
||||
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<ED, Cxt>(storageSchema).concat(triggers || []);
|
||||
const debugStore = createDebugStore(
|
||||
storageSchema,
|
||||
contextBuilder,
|
||||
backendContextBuilder,
|
||||
triggers2,
|
||||
checkers2,
|
||||
watchers || [],
|
||||
|
|
@ -80,12 +79,52 @@ export function initialize<
|
|||
actionDict
|
||||
);
|
||||
|
||||
const wrapper: AspectWrapper<ED, Cxt, typeof aspectDict2> = {
|
||||
} 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<ED, Cxt, typeof aspectDict2> = {
|
||||
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<ED, Cxt, typeof aspectDict2>(
|
||||
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,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<ED, Cxt, AD>,
|
||||
basicFeatures: BasicFeatures<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>,
|
||||
context: Cxt
|
||||
) => FD,
|
||||
contextBuilder: (cxtString?: string) => (store: RowStore<ED, Cxt>) => Cxt,
|
||||
frontendContextBuilder: (features: FD & BasicFeatures<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>) => (store: RowStore<ED, Cxt>) => Cxt,
|
||||
connector: Connector<ED, Cxt>,
|
||||
checkers?: Array<Checker<ED, keyof ED, Cxt>>,
|
||||
actionDict?: ActionDictOfEntityDict<ED>
|
||||
) {
|
||||
const cacheStore = new CacheStore(storageSchema, contextBuilder);
|
||||
const checkers2 = createDynamicCheckers<ED, Cxt>(storageSchema).concat(checkers || []);
|
||||
|
||||
const wrapper: AspectWrapper<ED, Cxt, AD & CommonAspectDict<ED, Cxt>> = {
|
||||
} as any;
|
||||
|
||||
const basicFeatures = initBasicFeatures<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>(
|
||||
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<ED, Cxt, AD & CommonAspectDict<ED, Cxt>> = {
|
||||
exec: async (name, params) => {
|
||||
const { result, opRecords } = await connector.callAspect(name as string, params, context);
|
||||
return {
|
||||
result,
|
||||
opRecords,
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
const basicFeatures = createBasicFeatures<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>(
|
||||
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,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,9 +34,9 @@ export function initialize<
|
|||
createFeatures: (
|
||||
aspectWrapper: AspectWrapper<ED, Cxt, AD>,
|
||||
basicFeatures: BasicFeatures<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>,
|
||||
context: Cxt
|
||||
) => FD,
|
||||
contextBuilder: (cxtString?: string) => (store: RowStore<ED, Cxt>) => Cxt,
|
||||
frontendContextBuilder: (features: FD & BasicFeatures<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>) => (store: RowStore<ED, Cxt>) => Cxt,
|
||||
backendContextBuilder: (contextStr?: string) => (store: RowStore<ED, Cxt>) => Promise<Cxt>,
|
||||
aspectDict: AD,
|
||||
exceptionRouters: ExceptionRouters = [],
|
||||
triggers?: Array<Trigger<ED, keyof ED, Cxt>>,
|
||||
|
|
@ -48,10 +48,11 @@ export function initialize<
|
|||
actionDict?: ActionDictOfEntityDict<ED>,
|
||||
i18nOptions?: I18nOptions
|
||||
) {
|
||||
const { features, context } = initDev<ED, Cxt, AD, FD>(
|
||||
const { features } = initDev<ED, Cxt, AD, FD>(
|
||||
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,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,9 +34,9 @@ export function initialize<
|
|||
createFeatures: (
|
||||
aspectWrapper: AspectWrapper<ED, Cxt, AD>,
|
||||
basicFeatures: BasicFeatures<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>,
|
||||
context: Cxt
|
||||
) => FD,
|
||||
contextBuilder: (cxtString?: string) => (store: RowStore<ED, Cxt>) => Cxt,
|
||||
frontendContextBuilder: (features: FD & BasicFeatures<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>) => (store: RowStore<ED, Cxt>) => Cxt,
|
||||
backendContextBuilder: (contextStr?: string) => (store: RowStore<ED, Cxt>) => Promise<Cxt>,
|
||||
aspectDict: AD,
|
||||
exceptionRouters: ExceptionRouters = [],
|
||||
triggers?: Array<Trigger<ED, keyof ED, Cxt>>,
|
||||
|
|
@ -48,10 +48,11 @@ export function initialize<
|
|||
actionDict?: ActionDictOfEntityDict<ED>,
|
||||
i18nOptions?: I18nOptions
|
||||
) {
|
||||
const { features, context } = initDev<ED, Cxt, AD, FD>(
|
||||
const { features } = initDev<ED, Cxt, AD, FD>(
|
||||
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,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,19 +33,18 @@ export function initialize<
|
|||
createFeatures: (
|
||||
aspectWrapper: AspectWrapper<ED, Cxt, AD>,
|
||||
basicFeatures: BasicFeatures<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>,
|
||||
context: Cxt
|
||||
) => FD,
|
||||
contextBuilder: (cxtString?: string) => (store: RowStore<ED, Cxt>) => Cxt,
|
||||
frontendContextBuilder: (features: FD & BasicFeatures<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>) => (store: RowStore<ED, Cxt>) => Cxt,
|
||||
exceptionRouters: ExceptionRouters = [],
|
||||
connector: Connector<ED, Cxt>,
|
||||
checkers?: Array<Checker<ED, keyof ED, Cxt>>,
|
||||
actionDict?: ActionDictOfEntityDict<ED>,
|
||||
i18nOptions?: I18nOptions
|
||||
) {
|
||||
const { features, context } = initProd<ED, Cxt, AD, FD>(
|
||||
const { features } = initProd<ED, Cxt, AD, FD>(
|
||||
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,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,19 +33,18 @@ export function initialize<
|
|||
createFeatures: (
|
||||
aspectWrapper: AspectWrapper<ED, Cxt, AD>,
|
||||
basicFeatures: BasicFeatures<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>,
|
||||
context: Cxt
|
||||
) => FD,
|
||||
contextBuilder: (cxtString?: string) => (store: RowStore<ED, Cxt>) => Cxt,
|
||||
frontendContextBuilder: (features: FD & BasicFeatures<ED, Cxt, AD & CommonAspectDict<ED, Cxt>>) => (store: RowStore<ED, Cxt>) => Cxt,
|
||||
exceptionRouters: ExceptionRouters = [],
|
||||
connector: Connector<ED, Cxt>,
|
||||
checkers?: Array<Checker<ED, keyof ED, Cxt>>,
|
||||
actionDict?: ActionDictOfEntityDict<ED>,
|
||||
i18nOptions?: I18nOptions
|
||||
) {
|
||||
const { features, context } = initProd<ED, Cxt, AD, FD>(
|
||||
const { features } = initProd<ED, Cxt, AD, FD>(
|
||||
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,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -667,8 +667,7 @@ export function makePageMethods<
|
|||
TData,
|
||||
TProperty,
|
||||
TMethod
|
||||
>,
|
||||
context: Cxt,
|
||||
>
|
||||
): OakPageMethods &
|
||||
ComponentThisType<ED, T, FormedData, IsList, TData, TProperty, TMethod> {
|
||||
return {
|
||||
|
|
@ -829,7 +828,6 @@ export function makePageMethods<
|
|||
: options.actions || [],
|
||||
},
|
||||
async () => {
|
||||
context.setScene(path2);
|
||||
this.refresh();
|
||||
options.methods?.onLoad &&
|
||||
(await options.methods.onLoad.call(
|
||||
|
|
|
|||
|
|
@ -264,11 +264,10 @@ function makePageMethods<
|
|||
TData,
|
||||
TProperty,
|
||||
TMethod
|
||||
>,
|
||||
context: Cxt,
|
||||
>
|
||||
): OakPageMethods &
|
||||
ComponentThisType<ED, T, FormedData, IsList, TData, TProperty, TMethod> {
|
||||
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<ED, Cxt, AD & CommonAspectDict<ED, Cxt>> & FD,
|
||||
exceptionRouterDict: Record<string, ExceptionHandler>,
|
||||
context: Cxt
|
||||
exceptionRouterDict: Record<string, ExceptionHandler>
|
||||
) {
|
||||
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<ED, Cxt, AD & CommonAspectDict<ED, Cxt>> & FD,
|
||||
exceptionRouterDict: Record<string, ExceptionHandler>,
|
||||
context: Cxt
|
||||
exceptionRouterDict: Record<string, ExceptionHandler>
|
||||
) {
|
||||
const {
|
||||
formData,
|
||||
|
|
|
|||
|
|
@ -190,11 +190,10 @@ function makePageMethods<
|
|||
TData,
|
||||
TProperty,
|
||||
TMethod
|
||||
>,
|
||||
context: Cxt
|
||||
>
|
||||
): OakPageMethods &
|
||||
ComponentThisType<ED, T, FormedData, IsList, TData, TProperty, TMethod> {
|
||||
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<ED, Cxt, AD & CommonAspectDict<ED, Cxt>> & FD,
|
||||
exceptionRouterDict: Record<string, ExceptionHandler>,
|
||||
context: Cxt
|
||||
exceptionRouterDict: Record<string, ExceptionHandler>
|
||||
) {
|
||||
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<ED, Cxt, AD & CommonAspectDict<ED, Cxt>> & FD,
|
||||
exceptionRouterDict: Record<string, ExceptionHandler>,
|
||||
context: Cxt
|
||||
) {
|
||||
const {
|
||||
formData,
|
||||
|
|
|
|||
Loading…
Reference in New Issue