From 710d75357ff31b46afd9142abae539306cbc81e0 Mon Sep 17 00:00:00 2001 From: "Xc@centOs" Date: Wed, 12 Apr 2023 21:21:40 +0800 Subject: [PATCH] =?UTF-8?q?ListNode=E5=90=88=E5=B9=B6=E8=87=AA=E8=BA=AB?= =?UTF-8?q?=E5=92=8C=E7=9B=B8=E5=BA=94=E5=AD=90=E7=BB=93=E7=82=B9=E7=9A=84?= =?UTF-8?q?action?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/features/runningTree.js | 34 +++++++++++++++++++++++++--------- lib/types/Page.d.ts | 2 +- src/features/runningTree.ts | 29 ++++++++++++++++++++--------- src/types/Page.ts | 2 +- 4 files changed, 47 insertions(+), 20 deletions(-) diff --git a/lib/features/runningTree.js b/lib/features/runningTree.js index d01f5185..1a311614 100644 --- a/lib/features/runningTree.js +++ b/lib/features/runningTree.js @@ -803,11 +803,29 @@ var ListNode = /** @class */ (function (_super) { operation: (0, lodash_1.cloneDeep)(this.updates[id].operation), }); } - for (var id in this.children) { - var childOperation = this.children[id].composeOperations(); + var _loop_1 = function (id) { + var childOperation = this_1.children[id].composeOperations(); if (childOperation) { - operations.push.apply(operations, tslib_1.__spreadArray([], tslib_1.__read(childOperation), false)); + // 现在因为后台有not null检查,不能先create再update,所以还是得合并成一个 + (0, assert_1.assert)(childOperation.length === 1); + var operation = childOperation[0].operation; + var action = operation.action, data = operation.data, filter = operation.filter; + (0, assert_1.assert)(!['create', 'remove'].includes(action), '在list结点上对子结点进行增删请使用父结点的addItem/removeItem,不要使用子结点的create/remove'); + (0, assert_1.assert)(filter.id === id); + var sameNodeOperation = operations.find(function (ele) { var _a; return ele.operation.action === 'create' && ele.operation.data.id === id || ((_a = ele.operation.filter) === null || _a === void 0 ? void 0 : _a.id) === id; }); + if (sameNodeOperation) { + if (sameNodeOperation.operation.action !== 'remove') { + Object.assign(sameNodeOperation.operation.data, data); + } + } + else { + operations.push.apply(operations, tslib_1.__spreadArray([], tslib_1.__read(childOperation), false)); + } } + }; + var this_1 = this; + for (var id in this.children) { + _loop_1(id); } return operations; }; @@ -1219,7 +1237,6 @@ var SingleNode = /** @class */ (function (_super) { SingleNode.prototype.composeOperations = function () { var _a, _b; if (this.dirty) { - var operations = []; var operation = this.operation ? (0, lodash_1.cloneDeep)(this.operation.operation) : { id: (0, uuid_1.generateNewId)(), action: 'update', @@ -1258,11 +1275,10 @@ var SingleNode = /** @class */ (function (_super) { } } } - operations.push({ - entity: this.entity, - operation: operation, - }); - return operations; + return [{ + entity: this.entity, + operation: operation, + }]; } }; SingleNode.prototype.getProjection = function (context, withDecendants) { diff --git a/lib/types/Page.d.ts b/lib/types/Page.d.ts index 6efafc53..8125cda7 100644 --- a/lib/types/Page.d.ts +++ b/lib/types/Page.d.ts @@ -231,7 +231,7 @@ export declare type OakComponentData = { +declare type OakListComoponetData = { oakFilters?: NonNullable[]; oakSorters?: NonNullable[]; oakPagination?: Pagination; diff --git a/src/features/runningTree.ts b/src/features/runningTree.ts index 9bc5fca8..dfbbb5b2 100644 --- a/src/features/runningTree.ts +++ b/src/features/runningTree.ts @@ -885,7 +885,23 @@ class ListNode< for (const id in this.children) { const childOperation = this.children[id].composeOperations(); if (childOperation) { - operations.push(...childOperation); + // 现在因为后台有not null检查,不能先create再update,所以还是得合并成一个 + assert(childOperation.length === 1); + const { operation } = childOperation[0]; + const { action, data, filter } = operation; + assert(!['create', 'remove'].includes(action), '在list结点上对子结点进行增删请使用父结点的addItem/removeItem,不要使用子结点的create/remove'); + assert(filter!.id === id); + const sameNodeOperation = operations.find( + ele => ele.operation.action === 'create' && (ele.operation.data as ED[T]['CreateSingle']['data']).id === id || ele.operation.filter?.id === id + ); + if (sameNodeOperation) { + if (sameNodeOperation.operation.action !== 'remove') { + Object.assign(sameNodeOperation.operation.data, data); + } + } + else { + operations.push(...childOperation); + } } } @@ -1295,10 +1311,6 @@ class SingleNode | undefined { if (this.dirty) { - const operations = [] as Array<{ - entity: keyof ED; - operation: ED[keyof ED]['Operation']; - }>; const operation: ED[T]['Operation'] = this.operation ? cloneDeep(this.operation.operation) : { id: generateNewId(), action: 'update', @@ -1340,11 +1352,10 @@ class SingleNode = {