debugStore中的cascadeSelect下降到根select去处理trigger,runningTree在composeOperation时尽可能把主键构造出来
This commit is contained in:
parent
2938e847fa
commit
fe4429a440
|
|
@ -16,7 +16,6 @@ export declare class DebugStore<ED extends EntityDict & BaseEntityDict, Cxt exte
|
|||
commit(txnId: string): Promise<void>;
|
||||
rollback(txnId: string): Promise<void>;
|
||||
protected cascadeUpdateAsync<T extends keyof ED, OP extends DebugStoreOperateOption>(entity: T, operation: ED[T]['Operation'], context: AsyncContext<ED>, option: OP): Promise<import("oak-domain/lib/types").OperationResult<ED>>;
|
||||
protected cascadeSelectAsync<T extends keyof ED, OP extends DebugStoreSelectOption>(entity: T, selection: ED[T]["Selection"], context: AsyncContext<ED>, option: OP): Promise<Partial<ED[T]["Schema"]>[]>;
|
||||
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, OP extends DebugStoreSelectOption>(entity: T, selection: ED[T]['Selection'], context: Cxt, option: OP): Promise<Partial<ED[T]["Schema"]>[]>;
|
||||
count<T extends keyof ED, OP extends SelectOption>(entity: T, selection: Pick<ED[T]["Selection"], "filter" | "count">, context: Cxt, option: OP): Promise<number>;
|
||||
|
|
|
|||
|
|
@ -47,33 +47,6 @@ var DebugStore = /** @class */ (function (_super) {
|
|||
});
|
||||
});
|
||||
};
|
||||
DebugStore.prototype.cascadeSelectAsync = 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.cascadeSelectAsync.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 () {
|
||||
return tslib_1.__generator(this, function (_a) {
|
||||
|
|
@ -84,9 +57,29 @@ var DebugStore = /** @class */ (function (_super) {
|
|||
};
|
||||
DebugStore.prototype.select = 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:
|
||||
(0, assert_1.default)(context.getCurrentTxnId());
|
||||
return [2 /*return*/, _super.prototype.selectAsync.call(this, entity, selection, context, option)];
|
||||
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.selectAsync.call(this, entity, selection, 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];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
|
|
|||
|
|
@ -128,86 +128,89 @@ function initializeWatchers(store, contextBuilder, watchers) {
|
|||
var count = 0;
|
||||
function doWatchers() {
|
||||
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
||||
var start, context, watchers_1, watchers_1_1, w, _a, entity, action, filter, actionData, filter2, _b, data, _c, result, _d, entity, projection, fn, filter, filter2, _e, projection2, _f, rows, result, err_1, e_1_1, duration;
|
||||
var e_1, _g;
|
||||
return tslib_1.__generator(this, function (_h) {
|
||||
switch (_h.label) {
|
||||
var start, context, watchers_1, watchers_1_1, w, _a, entity, action, filter, actionData, filter2, _b, data, _c, result, _d, _e, _f, _g, entity, projection, fn, filter, filter2, _h, projection2, _j, rows, result, err_1, e_1_1, duration;
|
||||
var e_1, _k, _l;
|
||||
return tslib_1.__generator(this, function (_m) {
|
||||
switch (_m.label) {
|
||||
case 0:
|
||||
count++;
|
||||
start = Date.now();
|
||||
return [4 /*yield*/, contextBuilder()(store)];
|
||||
case 1:
|
||||
context = _h.sent();
|
||||
_h.label = 2;
|
||||
context = _m.sent();
|
||||
_m.label = 2;
|
||||
case 2:
|
||||
_h.trys.push([2, 28, 29, 30]);
|
||||
_m.trys.push([2, 29, 30, 31]);
|
||||
watchers_1 = tslib_1.__values(watchers), watchers_1_1 = watchers_1.next();
|
||||
_h.label = 3;
|
||||
_m.label = 3;
|
||||
case 3:
|
||||
if (!!watchers_1_1.done) return [3 /*break*/, 27];
|
||||
if (!!watchers_1_1.done) return [3 /*break*/, 28];
|
||||
w = watchers_1_1.value;
|
||||
return [4 /*yield*/, context.begin()];
|
||||
case 4:
|
||||
_h.sent();
|
||||
_h.label = 5;
|
||||
_m.sent();
|
||||
_m.label = 5;
|
||||
case 5:
|
||||
_h.trys.push([5, 24, , 26]);
|
||||
if (!w.hasOwnProperty('actionData')) return [3 /*break*/, 13];
|
||||
_m.trys.push([5, 25, , 27]);
|
||||
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 = _h.sent();
|
||||
_b = _m.sent();
|
||||
return [3 /*break*/, 8];
|
||||
case 7:
|
||||
_b = filter;
|
||||
_h.label = 8;
|
||||
_m.label = 8;
|
||||
case 8:
|
||||
filter2 = _b;
|
||||
if (!(typeof actionData === 'function')) return [3 /*break*/, 10];
|
||||
return [4 /*yield*/, actionData()];
|
||||
case 9:
|
||||
_c = _h.sent();
|
||||
_c = _m.sent();
|
||||
return [3 /*break*/, 11];
|
||||
case 10:
|
||||
_c = actionData;
|
||||
_h.label = 11;
|
||||
_m.label = 11;
|
||||
case 11:
|
||||
data = _c;
|
||||
return [4 /*yield*/, store.operate(entity, {
|
||||
id: (0, uuid_1.generateNewId)(),
|
||||
action: action,
|
||||
data: data,
|
||||
filter: filter2
|
||||
}, context, {
|
||||
_e = (_d = store).operate;
|
||||
_f = [entity];
|
||||
_l = {};
|
||||
return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
|
||||
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:
|
||||
result = _h.sent();
|
||||
console.log("\u6267\u884C\u4E86watcher\u3010".concat(w.name, "\u3011\uFF0C\u7ED3\u679C\u662F\uFF1A"), result);
|
||||
return [3 /*break*/, 22];
|
||||
}]))];
|
||||
case 13:
|
||||
_d = w, entity = _d.entity, projection = _d.projection, fn = _d.fn, filter = _d.filter;
|
||||
if (!(typeof filter === 'function')) return [3 /*break*/, 15];
|
||||
return [4 /*yield*/, filter()];
|
||||
result = _m.sent();
|
||||
console.log("\u6267\u884C\u4E86watcher\u3010".concat(w.name, "\u3011\uFF0C\u7ED3\u679C\u662F\uFF1A"), result);
|
||||
return [3 /*break*/, 23];
|
||||
case 14:
|
||||
_e = _h.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:
|
||||
_e = filter;
|
||||
_h.label = 16;
|
||||
_h = _m.sent();
|
||||
return [3 /*break*/, 17];
|
||||
case 16:
|
||||
filter2 = _e;
|
||||
if (!(typeof projection === 'function')) return [3 /*break*/, 18];
|
||||
return [4 /*yield*/, projection()];
|
||||
_h = filter;
|
||||
_m.label = 17;
|
||||
case 17:
|
||||
_f = _h.sent();
|
||||
return [3 /*break*/, 19];
|
||||
filter2 = _h;
|
||||
if (!(typeof projection === 'function')) return [3 /*break*/, 19];
|
||||
return [4 /*yield*/, projection()];
|
||||
case 18:
|
||||
_f = projection;
|
||||
_h.label = 19;
|
||||
_j = _m.sent();
|
||||
return [3 /*break*/, 20];
|
||||
case 19:
|
||||
projection2 = _f;
|
||||
_j = projection;
|
||||
_m.label = 20;
|
||||
case 20:
|
||||
projection2 = _j;
|
||||
return [4 /*yield*/, store.select(entity, {
|
||||
data: projection2,
|
||||
filter: filter2,
|
||||
|
|
@ -215,39 +218,39 @@ function initializeWatchers(store, contextBuilder, watchers) {
|
|||
dontCollect: true,
|
||||
blockTrigger: true,
|
||||
})];
|
||||
case 20:
|
||||
rows = _h.sent();
|
||||
return [4 /*yield*/, fn(context, rows)];
|
||||
case 21:
|
||||
result = _h.sent();
|
||||
rows = _m.sent();
|
||||
return [4 /*yield*/, fn(context, rows)];
|
||||
case 22:
|
||||
result = _m.sent();
|
||||
console.log("\u6267\u884C\u4E86watcher\u3010".concat(w.name, "\u3011\uFF0C\u7ED3\u679C\u662F\uFF1A"), result);
|
||||
_h.label = 22;
|
||||
case 22: return [4 /*yield*/, context.commit()];
|
||||
case 23:
|
||||
_h.sent();
|
||||
return [3 /*break*/, 26];
|
||||
_m.label = 23;
|
||||
case 23: return [4 /*yield*/, context.commit()];
|
||||
case 24:
|
||||
err_1 = _h.sent();
|
||||
return [4 /*yield*/, context.rollback()];
|
||||
_m.sent();
|
||||
return [3 /*break*/, 27];
|
||||
case 25:
|
||||
_h.sent();
|
||||
console.error("\u6267\u884C\u4E86watcher\u3010".concat(w.name, "\u3011\uFF0C\u53D1\u751F\u9519\u8BEF\uFF1A"), err_1);
|
||||
return [3 /*break*/, 26];
|
||||
err_1 = _m.sent();
|
||||
return [4 /*yield*/, context.rollback()];
|
||||
case 26:
|
||||
_m.sent();
|
||||
console.error("\u6267\u884C\u4E86watcher\u3010".concat(w.name, "\u3011\uFF0C\u53D1\u751F\u9519\u8BEF\uFF1A"), err_1);
|
||||
return [3 /*break*/, 27];
|
||||
case 27:
|
||||
watchers_1_1 = watchers_1.next();
|
||||
return [3 /*break*/, 3];
|
||||
case 27: return [3 /*break*/, 30];
|
||||
case 28:
|
||||
e_1_1 = _h.sent();
|
||||
e_1 = { error: e_1_1 };
|
||||
return [3 /*break*/, 30];
|
||||
case 28: return [3 /*break*/, 31];
|
||||
case 29:
|
||||
e_1_1 = _m.sent();
|
||||
e_1 = { error: e_1_1 };
|
||||
return [3 /*break*/, 31];
|
||||
case 30:
|
||||
try {
|
||||
if (watchers_1_1 && !watchers_1_1.done && (_g = watchers_1.return)) _g.call(watchers_1);
|
||||
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 30:
|
||||
case 31:
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -1426,29 +1426,15 @@ var SingleNode = /** @class */ (function (_super) {
|
|||
if (!this.dirty) {
|
||||
return;
|
||||
}
|
||||
if (!this.operation) {
|
||||
var operation_1 = {
|
||||
var filter = this.getFilter();
|
||||
var operation = this.operation ? (0, lodash_1.cloneDeep)(this.operation.operation) : {
|
||||
id: (0, uuid_1.generateNewId)(),
|
||||
action: 'update',
|
||||
data: {},
|
||||
};
|
||||
if (this.id) {
|
||||
Object.assign(operation_1, {
|
||||
filter: {
|
||||
id: this.id,
|
||||
}
|
||||
});
|
||||
}
|
||||
this.operation = {
|
||||
operation: operation_1,
|
||||
};
|
||||
}
|
||||
var operation = (0, lodash_1.cloneDeep)(this.operation.operation);
|
||||
if (this.id && !operation.filter) {
|
||||
if (filter) {
|
||||
Object.assign(operation, {
|
||||
filter: {
|
||||
id: this.id,
|
||||
}
|
||||
filter: filter,
|
||||
});
|
||||
}
|
||||
for (var ele in this.children) {
|
||||
|
|
@ -1592,26 +1578,20 @@ var SingleNode = /** @class */ (function (_super) {
|
|||
* @returns
|
||||
*/
|
||||
SingleNode.prototype.getParentFilter = function (childNode) {
|
||||
var _a, _b, _c;
|
||||
var _a, _b, _c, _d;
|
||||
var filter = this.getFilter(true);
|
||||
var value = this.getFreshValue();
|
||||
var id = this.id;
|
||||
for (var key in this.children) {
|
||||
if (childNode === this.children[key]) {
|
||||
var sliceIdx = key.indexOf(':');
|
||||
var key2 = sliceIdx > 0 ? key.slice(0, sliceIdx) : key;
|
||||
// 此时如果operation中有相关的外键被设置则直接返回
|
||||
var operationData = undefined;
|
||||
if (this.operation) {
|
||||
var _d = this.operation.operation, action = _d.action, data = _d.data;
|
||||
if (action !== 'remove') {
|
||||
operationData = data;
|
||||
}
|
||||
}
|
||||
var rel = this.judgeRelation(key2);
|
||||
if (rel === 2) {
|
||||
// 基于entity/entityId的多对一
|
||||
if (operationData === null || operationData === void 0 ? void 0 : operationData.entityId) {
|
||||
if (value === null || value === void 0 ? void 0 : value.entityId) {
|
||||
return {
|
||||
id: operationData.entityId,
|
||||
id: value.entityId,
|
||||
};
|
||||
}
|
||||
else if (filter) {
|
||||
|
|
@ -1634,9 +1614,9 @@ var SingleNode = /** @class */ (function (_super) {
|
|||
}
|
||||
}
|
||||
else if (typeof rel === 'string') {
|
||||
if (operationData && operationData["".concat(rel, "Id")]) {
|
||||
if (value && value["".concat(rel, "Id")]) {
|
||||
return {
|
||||
id: operationData["".concat(rel, "Id")],
|
||||
id: value["".concat(rel, "Id")],
|
||||
};
|
||||
}
|
||||
else if (filter) {
|
||||
|
|
@ -1658,24 +1638,40 @@ var SingleNode = /** @class */ (function (_super) {
|
|||
}
|
||||
else {
|
||||
(0, assert_1.assert)(rel instanceof Array);
|
||||
if (filter) {
|
||||
if (rel[1]) {
|
||||
// 基于普通外键的一对多
|
||||
if (id || value) {
|
||||
return _b = {},
|
||||
_b[rel[1].slice(0, rel[1].length - 2)] = filter,
|
||||
_b[rel[1]] = id || value.id,
|
||||
_b;
|
||||
}
|
||||
else {
|
||||
// 基于entity/entityId的一对多
|
||||
else if (filter) {
|
||||
return _c = {},
|
||||
_c[this.entity] = filter,
|
||||
_c[rel[1].slice(0, rel[1].length - 2)] = filter,
|
||||
_c;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// 基于entity/entityId的一对多
|
||||
if (id || value) {
|
||||
return {
|
||||
entity: this.entity,
|
||||
entityId: id || value.id,
|
||||
};
|
||||
}
|
||||
else if (filter) {
|
||||
return _d = {},
|
||||
_d[this.entity] = filter,
|
||||
_d;
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
(0, assert_1.assert)(false);
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ var oakBehavior = Behavior({
|
|||
});
|
||||
},
|
||||
reRender: function () {
|
||||
return page_common_1.reRender.call(this, this.option);
|
||||
return page_common_1.reRender.call(this, this.oakOption);
|
||||
},
|
||||
onLoad: function (query) {
|
||||
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
||||
|
|
@ -78,7 +78,7 @@ var oakBehavior = Behavior({
|
|||
return tslib_1.__generator(this, function (_b) {
|
||||
switch (_b.label) {
|
||||
case 0:
|
||||
_a = this.option, properties = _a.properties, path = _a.path;
|
||||
_a = this.oakOption, properties = _a.properties, path = _a.path;
|
||||
assignProps = function (data, property, type) {
|
||||
var _a;
|
||||
if (data[property]) {
|
||||
|
|
@ -126,7 +126,7 @@ var oakBehavior = Behavior({
|
|||
}
|
||||
}
|
||||
if (!(this.props.oakPath || (this.iAmThePage() && path))) return [3 /*break*/, 2];
|
||||
return [4 /*yield*/, page_common_1.onPathSet.call(this, this.option)];
|
||||
return [4 /*yield*/, page_common_1.onPathSet.call(this, this.oakOption)];
|
||||
case 1:
|
||||
_b.sent();
|
||||
return [3 /*break*/, 3];
|
||||
|
|
@ -166,7 +166,7 @@ var oakBehavior = Behavior({
|
|||
case 0:
|
||||
if (!(!this.state.oakLoadingMore &&
|
||||
this.iAmThePage() &&
|
||||
this.option.isList)) return [3 /*break*/, 2];
|
||||
this.oakOption.isList)) return [3 /*break*/, 2];
|
||||
return [4 /*yield*/, this.loadMore()];
|
||||
case 1:
|
||||
_a.sent();
|
||||
|
|
@ -372,7 +372,7 @@ var oakBehavior = Behavior({
|
|||
observers: {
|
||||
oakPath: function (data) {
|
||||
if (data) {
|
||||
page_common_1.onPathSet.call(this, this.option);
|
||||
page_common_1.onPathSet.call(this, this.oakOption);
|
||||
}
|
||||
},
|
||||
oakId: function (data) {
|
||||
|
|
@ -381,12 +381,12 @@ var oakBehavior = Behavior({
|
|||
},
|
||||
pageLifetimes: {
|
||||
show: function () {
|
||||
var show = (this.option.lifetimes || {}).show;
|
||||
var show = (this.oakOption.lifetimes || {}).show;
|
||||
this.reRender();
|
||||
show && show.call(this);
|
||||
},
|
||||
hide: function () {
|
||||
var hide = (this.option.lifetimes || {}).hide;
|
||||
var hide = (this.oakOption.lifetimes || {}).hide;
|
||||
hide && hide.call(this);
|
||||
},
|
||||
},
|
||||
|
|
@ -404,46 +404,15 @@ var oakBehavior = Behavior({
|
|||
});
|
||||
};
|
||||
},
|
||||
attached: function () {
|
||||
var _a;
|
||||
var attached = (this.option.lifetimes || {}).attached;
|
||||
var i18nInstance = (0, i18n_1.getI18nInstanceWechatMp)();
|
||||
if (i18nInstance) {
|
||||
this.setState((_a = {},
|
||||
_a[i18n_1.CURRENT_LOCALE_KEY] = i18nInstance.currentLocale,
|
||||
_a[i18n_1.CURRENT_LOCALE_DATA] = i18nInstance.translations,
|
||||
_a));
|
||||
}
|
||||
attached && attached.call(this);
|
||||
},
|
||||
detached: function () {
|
||||
this.state.oakFullpath &&
|
||||
(this.iAmThePage() || this.props.oakAutoUnmount) &&
|
||||
page_common_1.destroyNode.call(this);
|
||||
var detached = (this.option.lifetimes || {}).detached;
|
||||
detached && detached.call(this);
|
||||
},
|
||||
ready: function () {
|
||||
var ready = (this.option.lifetimes || {}).ready;
|
||||
ready && ready.call(this);
|
||||
},
|
||||
moved: function () {
|
||||
var moved = (this.option.lifetimes || {}).moved;
|
||||
moved && moved.call(this);
|
||||
},
|
||||
error: function (err) {
|
||||
var error = (this.option.lifetimes || {}).error;
|
||||
error && error.call(this, err);
|
||||
},
|
||||
},
|
||||
});
|
||||
function createComponent(option, features) {
|
||||
var data = option.data, properties = option.properties, methods = option.methods, wechatMp = option.wechatMp, lifetimes = option.lifetimes, observers = option.observers;
|
||||
var _a = lifetimes || {}, attached = _a.attached, show = _a.show, hide = _a.hide, created = _a.created, detached = _a.detached, restLifetimes = tslib_1.__rest(_a, ["attached", "show", "hide", "created", "detached"]);
|
||||
var _a = lifetimes || {}, attached = _a.attached, show = _a.show, hide = _a.hide, created = _a.created, detached = _a.detached, ready = _a.ready, moved = _a.moved, error = _a.error;
|
||||
var _b = wechatMp || {}, options = _b.options, externalClasses = _b.externalClasses;
|
||||
return Component({
|
||||
externalClasses: externalClasses,
|
||||
options: options,
|
||||
// options,
|
||||
behaviors: [oakBehavior],
|
||||
data: Object.assign({}, data, {
|
||||
oakFullpath: '',
|
||||
|
|
@ -453,7 +422,7 @@ function createComponent(option, features) {
|
|||
observers: tslib_1.__assign({}, observers),
|
||||
pageLifetimes: {
|
||||
show: function () {
|
||||
this.reRender();
|
||||
// this.reRender();
|
||||
show && show.call(this);
|
||||
},
|
||||
hide: function () {
|
||||
|
|
@ -464,8 +433,40 @@ function createComponent(option, features) {
|
|||
created: function () {
|
||||
this.oakOption = option;
|
||||
this.features = features;
|
||||
this.subscribed = [];
|
||||
created && created.call(this);
|
||||
},
|
||||
attached: function () {
|
||||
var _a;
|
||||
var _this = this;
|
||||
var i18nInstance = (0, i18n_1.getI18nInstanceWechatMp)();
|
||||
if (i18nInstance) {
|
||||
this.setState((_a = {},
|
||||
_a[i18n_1.CURRENT_LOCALE_KEY] = i18nInstance.currentLocale,
|
||||
_a[i18n_1.CURRENT_LOCALE_DATA] = i18nInstance.translations,
|
||||
_a));
|
||||
}
|
||||
if (option.entity) {
|
||||
this.subscribed.push(features.cache.subscribe(function () { return _this.reRender(); }));
|
||||
}
|
||||
attached && attached.call(this);
|
||||
},
|
||||
detached: function () {
|
||||
this.subscribed.forEach(function (ele) { return ele(); });
|
||||
this.state.oakFullpath &&
|
||||
(this.iAmThePage() || this.props.oakAutoUnmount) &&
|
||||
page_common_1.destroyNode.call(this);
|
||||
detached && detached.call(this);
|
||||
},
|
||||
ready: function () {
|
||||
ready && ready.call(this);
|
||||
},
|
||||
moved: function () {
|
||||
moved && moved.call(this);
|
||||
},
|
||||
error: function (err) {
|
||||
error && error.call(this, err);
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,21 +41,6 @@ export class DebugStore<ED extends EntityDict & BaseEntityDict, Cxt extends Asyn
|
|||
return result;
|
||||
}
|
||||
|
||||
protected async cascadeSelectAsync<T extends keyof ED, OP extends DebugStoreSelectOption>(entity: T, selection: ED[T]["Selection"], context: AsyncContext<ED>, option: OP) {
|
||||
const selection2 = Object.assign({
|
||||
action: 'select',
|
||||
}, selection) as ED[T]['Operation'];
|
||||
|
||||
if (!option.blockTrigger) {
|
||||
await this.executor.preOperation(entity, selection2, context, option);
|
||||
}
|
||||
const result = await super.cascadeSelectAsync(entity, selection2, context, option);
|
||||
if (!option.blockTrigger) {
|
||||
await this.executor.postOperation(entity, selection2, context, option, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
async operate<T extends keyof ED, OP extends DebugStoreOperateOption>(
|
||||
entity: T,
|
||||
operation: ED[T]['Operation'],
|
||||
|
|
@ -73,7 +58,20 @@ export class DebugStore<ED extends EntityDict & BaseEntityDict, Cxt extends Asyn
|
|||
option: OP
|
||||
) {
|
||||
assert(context.getCurrentTxnId());
|
||||
return super.selectAsync(entity, selection, context, option);
|
||||
const selection2 = Object.assign({
|
||||
action: 'select',
|
||||
}, selection) as ED[T]['Operation'];
|
||||
|
||||
// select的trigger应加在根结点的动作之前
|
||||
if (!option.blockTrigger) {
|
||||
await this.executor.preOperation(entity, selection2, context, option);
|
||||
}
|
||||
const result = await super.selectAsync(entity, selection, context, option);
|
||||
|
||||
if (!option.blockTrigger) {
|
||||
await this.executor.postOperation(entity, selection2, context, option, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
async count<T extends keyof ED, OP extends SelectOption>(entity: T, selection: Pick<ED[T]["Selection"], "filter" | "count">, context: Cxt, option: OP): Promise<number> {
|
||||
|
|
|
|||
|
|
@ -1402,29 +1402,15 @@ class SingleNode<ED extends EntityDict & BaseEntityDict,
|
|||
if (!this.dirty) {
|
||||
return;
|
||||
}
|
||||
if (!this.operation) {
|
||||
const operation: ED[T]['Update'] = {
|
||||
const filter = this.getFilter();
|
||||
const operation: ED[T]['Update'] = this.operation ? cloneDeep(this.operation.operation) : {
|
||||
id: generateNewId(),
|
||||
action: 'update',
|
||||
data: {},
|
||||
};
|
||||
if (this.id) {
|
||||
if (filter) {
|
||||
Object.assign(operation, {
|
||||
filter: {
|
||||
id: this.id!,
|
||||
}
|
||||
});
|
||||
}
|
||||
this.operation = {
|
||||
operation,
|
||||
};
|
||||
}
|
||||
let operation: ED[T]['Update'] = cloneDeep(this.operation.operation);
|
||||
if (this.id && !operation.filter) {
|
||||
Object.assign(operation, {
|
||||
filter: {
|
||||
id: this.id,
|
||||
}
|
||||
filter,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -1458,7 +1444,7 @@ class SingleNode<ED extends EntityDict & BaseEntityDict,
|
|||
|
||||
return [{
|
||||
entity: this.entity,
|
||||
operation,
|
||||
operation: operation!,
|
||||
}];
|
||||
}
|
||||
|
||||
|
|
@ -1564,26 +1550,19 @@ class SingleNode<ED extends EntityDict & BaseEntityDict,
|
|||
*/
|
||||
getParentFilter<T2 extends keyof ED>(childNode: Node<ED, keyof ED, Cxt, FrontCxt, AD>): ED[T2]['Selection']['filter'] | undefined {
|
||||
const filter = this.getFilter(true);
|
||||
const value = this.getFreshValue();
|
||||
const id = this.id;
|
||||
|
||||
for (const key in this.children) {
|
||||
if (childNode === this.children[key]) {
|
||||
const sliceIdx = key.indexOf(':');
|
||||
const key2 = sliceIdx > 0 ? key.slice(0, sliceIdx) : key;
|
||||
|
||||
// 此时如果operation中有相关的外键被设置则直接返回
|
||||
let operationData: ED[T]['Update']['data'] | undefined = undefined;
|
||||
if (this.operation) {
|
||||
const { operation: { action, data } } = this.operation;
|
||||
if (action !== 'remove') {
|
||||
operationData = data;
|
||||
}
|
||||
}
|
||||
const rel = this.judgeRelation(key2);
|
||||
if (rel === 2) {
|
||||
// 基于entity/entityId的多对一
|
||||
if (operationData?.entityId) {
|
||||
if (value?.entityId) {
|
||||
return {
|
||||
id: operationData!.entityId!,
|
||||
id: value!.entityId!,
|
||||
};
|
||||
}
|
||||
else if (filter) {
|
||||
|
|
@ -1606,9 +1585,9 @@ class SingleNode<ED extends EntityDict & BaseEntityDict,
|
|||
}
|
||||
}
|
||||
else if (typeof rel === 'string') {
|
||||
if (operationData && operationData[`${rel}Id`]) {
|
||||
if (value && value[`${rel}Id`]) {
|
||||
return {
|
||||
id: operationData[`${rel}Id`],
|
||||
id: value[`${rel}Id`],
|
||||
};
|
||||
}
|
||||
else if (filter) {
|
||||
|
|
@ -1630,26 +1609,42 @@ class SingleNode<ED extends EntityDict & BaseEntityDict,
|
|||
}
|
||||
else {
|
||||
assert(rel instanceof Array);
|
||||
if (filter) {
|
||||
if (rel[1]) {
|
||||
// 基于普通外键的一对多
|
||||
if (id || value) {
|
||||
return {
|
||||
[rel[1]]: id || value!.id,
|
||||
};
|
||||
}
|
||||
else if (filter) {
|
||||
return {
|
||||
[rel[1].slice(0, rel[1].length - 2)]: filter,
|
||||
};
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// 基于entity/entityId的一对多
|
||||
if (id || value) {
|
||||
return {
|
||||
entity: this.entity,
|
||||
entityId: id || value!.id,
|
||||
};
|
||||
}
|
||||
else if (filter) {
|
||||
return {
|
||||
[this.entity]: filter,
|
||||
};
|
||||
}
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue