From ea01036c5a26475b8e2391537dc7a152175718a5 Mon Sep 17 00:00:00 2001 From: Xc Date: Fri, 26 Dec 2025 11:02:21 +0800 Subject: [PATCH] =?UTF-8?q?runningTree=E5=9C=A8=E7=9B=B4=E6=8E=A5execute?= =?UTF-8?q?=E6=9F=90=E4=B8=AAaction=E6=97=B6=EF=BC=8C=E7=AE=80=E5=8C=96?= =?UTF-8?q?=E4=BA=86=E5=8E=9F=E5=85=88=E7=9A=84=E8=A1=8C=E4=B8=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- es/features/runningTree.d.ts | 2 +- es/features/runningTree.js | 41 ++++++++++++++++++++++----------- lib/features/runningTree.d.ts | 2 +- lib/features/runningTree.js | 39 +++++++++++++++++++++---------- package.json | 2 +- src/features/runningTree.ts | 43 +++++++++++++++++++++++------------ 6 files changed, 87 insertions(+), 42 deletions(-) diff --git a/es/features/runningTree.d.ts b/es/features/runningTree.d.ts index e73f8fc9..90843e12 100644 --- a/es/features/runningTree.d.ts +++ b/es/features/runningTree.d.ts @@ -233,7 +233,7 @@ declare class SingleNode): void; refresh(): Promise; clean(lsn?: number, dontPublish?: true): void; - private getFilter; + getFilter(ignoreNew?: true, onlyHot?: true): ED[T]['Filter'] | undefined; getIntrinsticFilters(): ED[T]["Filter"] | undefined; /** * getParentFilter不能假设一定已经有数据,只能根据当前filter的条件去构造 diff --git a/es/features/runningTree.js b/es/features/runningTree.js index 1362a078..1f613456 100644 --- a/es/features/runningTree.js +++ b/es/features/runningTree.js @@ -5,7 +5,7 @@ import { createOperationsFromModies } from 'oak-domain/lib/store/modi'; import { judgeRelation } from "oak-domain/lib/store/relation"; import { CreateAtAttribute, UpdateAtAttribute, DeleteAtAttribute } from "oak-domain/lib/types"; import { Feature } from '../types/Feature'; -import { generateNewId } from 'oak-domain/lib/utils/uuid'; +import { generateNewId, generateNewIdAsync } from 'oak-domain/lib/utils/uuid'; export const MODI_NEXT_PATH_SUFFIX = ':next'; const START_LSN = 100; function mergeOperation(schema, entity, oper1, oper2) { @@ -2413,7 +2413,7 @@ export class RunningTree extends Feature { const node = path && this.findNode(path); // assert(node.isDirty()); node && node.setExecuting(true); - let pollute = false; + // let pollute = false; try { let operations = path && this.getOperations(path) || []; if (opers) { @@ -2432,15 +2432,30 @@ export class RunningTree extends Feature { else if (node) { // 老的写法,直接对一个非脏的结点execute某个action,也可以支持 assert(node instanceof SingleNode); - node.update(this.logSerailNumber, {}, action); - pollute = true; - operations = node.composeOperations() || []; - assert(operations.length === 1); - const [operation1] = operations; - if (action !== operation1.operation.action) { - assert(operation1.operation.action === 'update'); // 如果execute时传action,前面update动作应该只可能是update - operation1.operation.action = action; - } + // node.update(this.logSerailNumber, {}, action); + // pollute = true; + // operations = node.composeOperations() || []; + // assert(operations.length === 1); + // const [operation1] = operations; + // if (action !== operation1.operation.action) { + // assert(operation1.operation.action === 'update'); // 如果execute时传action,前面update动作应该只可能是update + // operation1.operation.action = action; + // } + /** + * 上述写法会触发publish行为,如:一个close动作会导致页面像下面这样渲染: + * opened --> closed(上面的node.update) --> opened(执行成功回来setExecuting时) --> closed(执行成功回来再sync cache后) + */ + operations.push({ + entity: node.getEntity(), + operation: { + id: await generateNewIdAsync(), + action, + data: { + $$updateAt$$: Date.now(), + }, + filter: node.getFilter(true), + } + }); } } if (operations.length > 0) { @@ -2470,9 +2485,9 @@ export class RunningTree extends Feature { } catch (err) { node && node.setExecuting(false); - if (pollute) { + /* if (pollute) { path && this.clean(path); - } + } */ throw err; } } diff --git a/lib/features/runningTree.d.ts b/lib/features/runningTree.d.ts index e73f8fc9..90843e12 100644 --- a/lib/features/runningTree.d.ts +++ b/lib/features/runningTree.d.ts @@ -233,7 +233,7 @@ declare class SingleNode): void; refresh(): Promise; clean(lsn?: number, dontPublish?: true): void; - private getFilter; + getFilter(ignoreNew?: true, onlyHot?: true): ED[T]['Filter'] | undefined; getIntrinsticFilters(): ED[T]["Filter"] | undefined; /** * getParentFilter不能假设一定已经有数据,只能根据当前filter的条件去构造 diff --git a/lib/features/runningTree.js b/lib/features/runningTree.js index 9d49b996..78b85f8a 100644 --- a/lib/features/runningTree.js +++ b/lib/features/runningTree.js @@ -2416,7 +2416,7 @@ class RunningTree extends Feature_1.Feature { const node = path && this.findNode(path); // assert(node.isDirty()); node && node.setExecuting(true); - let pollute = false; + // let pollute = false; try { let operations = path && this.getOperations(path) || []; if (opers) { @@ -2435,15 +2435,30 @@ class RunningTree extends Feature_1.Feature { else if (node) { // 老的写法,直接对一个非脏的结点execute某个action,也可以支持 (0, assert_1.assert)(node instanceof SingleNode); - node.update(this.logSerailNumber, {}, action); - pollute = true; - operations = node.composeOperations() || []; - (0, assert_1.assert)(operations.length === 1); - const [operation1] = operations; - if (action !== operation1.operation.action) { - (0, assert_1.assert)(operation1.operation.action === 'update'); // 如果execute时传action,前面update动作应该只可能是update - operation1.operation.action = action; - } + // node.update(this.logSerailNumber, {}, action); + // pollute = true; + // operations = node.composeOperations() || []; + // assert(operations.length === 1); + // const [operation1] = operations; + // if (action !== operation1.operation.action) { + // assert(operation1.operation.action === 'update'); // 如果execute时传action,前面update动作应该只可能是update + // operation1.operation.action = action; + // } + /** + * 上述写法会触发publish行为,如:一个close动作会导致页面像下面这样渲染: + * opened --> closed(上面的node.update) --> opened(执行成功回来setExecuting时) --> closed(执行成功回来再sync cache后) + */ + operations.push({ + entity: node.getEntity(), + operation: { + id: await (0, uuid_1.generateNewIdAsync)(), + action, + data: { + $$updateAt$$: Date.now(), + }, + filter: node.getFilter(true), + } + }); } } if (operations.length > 0) { @@ -2473,9 +2488,9 @@ class RunningTree extends Feature_1.Feature { } catch (err) { node && node.setExecuting(false); - if (pollute) { + /* if (pollute) { path && this.clean(path); - } + } */ throw err; } } diff --git a/package.json b/package.json index fa733459..6b75e003 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,7 @@ "@types/node": "^20.7.0", "@types/node-schedule": "^2.1.0", "@types/nprogress": "^0.2.3", - "@types/react": "^18.3.26", + "@types/react": "^18.3.27", "@types/react-dom": "^18.2.14", "@types/react-native": "^0.72.8", "@types/uuid": "^9.0.6", diff --git a/src/features/runningTree.ts b/src/features/runningTree.ts index b3e9a766..17c721f0 100644 --- a/src/features/runningTree.ts +++ b/src/features/runningTree.ts @@ -12,7 +12,7 @@ import { Cache } from './cache'; import { Pagination } from '../types/Pagination'; import { Feature } from '../types/Feature'; import { ActionDef, CreateDataDef } from '../types/Page'; -import { generateNewId } from 'oak-domain/lib/utils/uuid'; +import { generateNewId, generateNewIdAsync } from 'oak-domain/lib/utils/uuid'; export const MODI_NEXT_PATH_SUFFIX = ':next'; const START_LSN = 100; @@ -1965,7 +1965,7 @@ class SingleNode extends Feature node && node.setExecuting(true); - let pollute = false; + // let pollute = false; try { let operations = path && this.getOperations(path) || []; if (opers) { @@ -2990,15 +2990,30 @@ export class RunningTree extends Feature else if (node) { // 老的写法,直接对一个非脏的结点execute某个action,也可以支持 assert(node instanceof SingleNode); - node.update(this.logSerailNumber, {}, action); - pollute = true; - operations = node.composeOperations() || []; - assert(operations.length === 1); - const [operation1] = operations; - if (action !== operation1.operation.action) { - assert(operation1.operation.action === 'update'); // 如果execute时传action,前面update动作应该只可能是update - operation1.operation.action = action; - } + // node.update(this.logSerailNumber, {}, action); + // pollute = true; + // operations = node.composeOperations() || []; + // assert(operations.length === 1); + // const [operation1] = operations; + // if (action !== operation1.operation.action) { + // assert(operation1.operation.action === 'update'); // 如果execute时传action,前面update动作应该只可能是update + // operation1.operation.action = action; + // } + /** + * 上述写法会触发publish行为,如:一个close动作会导致页面像下面这样渲染: + * opened --> closed(上面的node.update) --> opened(执行成功回来setExecuting时) --> closed(执行成功回来再sync cache后) + */ + operations.push({ + entity: node.getEntity(), + operation: { + id: await generateNewIdAsync(), + action, + data: { + $$updateAt$$: Date.now(), + }, + filter: node.getFilter(true), + } + }); } } if (operations.length > 0) { @@ -3038,9 +3053,9 @@ export class RunningTree extends Feature return { message: 'No Operation' }; } catch (err) { node && node.setExecuting(false); - if (pollute) { + /* if (pollute) { path && this.clean(path); - } + } */ throw err; } }