From e6f298af7120d6fc808e00b8df22a8ce69f3f990 Mon Sep 17 00:00:00 2001 From: roymondchen Date: Thu, 22 Aug 2024 19:05:06 +0800 Subject: [PATCH] =?UTF-8?q?fix(data-source):=20=E8=BF=AD=E4=BB=A3=E5=86=85?= =?UTF-8?q?=E5=AE=B9=E5=A4=9A=E5=B1=82=E5=B5=8C=E5=A5=97=E4=B8=8B=E5=AD=90?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E6=9D=A1=E4=BB=B6=E9=85=8D=E7=BD=AE=E4=B8=8D?= =?UTF-8?q?=E7=94=9F=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/data-source/src/DataSourceManager.ts | 17 +++++++---------- packages/data-source/src/utils.ts | 14 +++++++++++++- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/packages/data-source/src/DataSourceManager.ts b/packages/data-source/src/DataSourceManager.ts index ae4a4931e..136f7bb49 100644 --- a/packages/data-source/src/DataSourceManager.ts +++ b/packages/data-source/src/DataSourceManager.ts @@ -250,20 +250,17 @@ class DataSourceManager extends EventEmitter { return nodes; } - return nodes.map((item) => { - const node = compliedIteratorItem({ + return nodes.map((item) => + compliedIteratorItem({ compile: (value: any) => compiledNodeField(value, ctxData), dsId: ds.id, item, deps, - }); - - if (condDeps[node.id]?.keys.length && this.app.platform !== 'editor') { - node.condResult = compliedConditions(node, ctxData); - } - - return node; - }); + condDeps, + inEditor: this.app.platform === 'editor', + ctxData, + }), + ); } public destroy() { diff --git a/packages/data-source/src/utils.ts b/packages/data-source/src/utils.ts index a6931e8c0..75706cdb0 100644 --- a/packages/data-source/src/utils.ts +++ b/packages/data-source/src/utils.ts @@ -191,17 +191,29 @@ export const compliedIteratorItem = ({ dsId, item, deps, + condDeps, + inEditor, + ctxData, }: { compile: (value: any) => any; dsId: string; item: MNode; deps: DepData; + condDeps: DepData; + inEditor: boolean; + ctxData: DataSourceManagerData; }) => { const { items, ...node } = item; const newNode = cloneDeep(node); + if (condDeps[node.id]?.keys.length && !inEditor) { + newNode.condResult = compliedConditions(node, ctxData); + } + if (Array.isArray(items) && items.length) { - newNode.items = items.map((item) => compliedIteratorItem({ compile, dsId, item, deps })); + newNode.items = items.map((item) => + compliedIteratorItem({ compile, dsId, item, deps, condDeps, inEditor, ctxData }), + ); } else if (items) { newNode.items = items; }