增加了buildContext选项,简化行为

This commit is contained in:
Xu Chang 2023-08-28 21:35:15 +08:00
parent f00f50b45a
commit b30a8b012b
8 changed files with 15 additions and 11 deletions

View File

@ -87,5 +87,6 @@ export declare class Cache<ED extends EntityDict & BaseEntityDict, Cxt extends A
begin(): FrontCxt;
commit(): void;
rollback(): void;
buildContext(): FrontCxt;
}
export {};

View File

@ -601,6 +601,9 @@ var Cache = /** @class */ (function (_super) {
this.context.rollback();
this.context = undefined;
};
Cache.prototype.buildContext = function () {
return this.contextBuilder();
};
return Cache;
}(Feature_1.Feature));
exports.Cache = Cache;

View File

@ -41,9 +41,8 @@ function initialize(storageSchema, frontendContextBuilder, backendContextBuilder
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
context = features2.cache.begin();
context = features2.cache.buildContext();
str = context.toString();
features2.cache.commit();
return [4 /*yield*/, backendContextBuilder(str)(debugStore)];
case 1:
contextBackend = _a.sent();

View File

@ -29,8 +29,7 @@ function initialize(storageSchema, frontendContextBuilder, connector, checkers,
return tslib_1.__generator(this, function (_b) {
switch (_b.label) {
case 0:
context = features2.cache.begin();
features.cache.commit();
context = features2.cache.buildContext();
return [4 /*yield*/, connector.callAspect(name, params, context)];
case 1:
_a = _b.sent(), result = _a.result, opRecords = _a.opRecords, message = _a.message;

View File

@ -23,9 +23,9 @@
"history": "^5.3.0",
"i18n-js": "^4.3.0",
"node-schedule": "^2.1.1",
"oak-common-aspect": "file:../oak-common-aspect",
"oak-domain": "file:../oak-domain",
"oak-memory-tree-store": "file:../oak-memory-tree-store",
"oak-common-aspect": "^2.2.1",
"oak-domain": "^3.0.2",
"oak-memory-tree-store": "^3.0.1",
"ol": "^7.3.0",
"react-scripts": "^5.0.1",
"rmc-pull-to-refresh": "^1.0.13",

View File

@ -637,4 +637,8 @@ export class Cache<
this.context.rollback();
this.context = undefined;
}
buildContext() {
return this.contextBuilder!();
}
}

View File

@ -96,9 +96,8 @@ export function initialize<
const wrapper: AspectWrapper<ED, Cxt, CommonAspectDict<ED, Cxt> & AD> = {
exec: async (name, params) => {
const context = features2.cache.begin();
const context = features2.cache.buildContext();
const str = context.toString();
features2.cache.commit();
const contextBackend = await backendContextBuilder(str)(debugStore);
await contextBackend.begin();
let result;

View File

@ -52,8 +52,7 @@ export function initialize<
const wrapper: AspectWrapper<ED, Cxt, AD & CommonAspectDict<ED, Cxt>> = {
exec: async (name, params) => {
const context = features2.cache.begin();
features.cache.commit();
const context = features2.cache.buildContext();
const { result, opRecords, message } = await connector.callAspect(name as string, params, context);
return {
result,