fix(data-source): 编辑器中迭代器容器中的容器添加组件并关联数据源后没有编译

This commit is contained in:
roymondchen 2024-09-19 19:51:48 +08:00 committed by roymondchen
parent 2885e81c8b
commit 8aba06ac38
2 changed files with 28 additions and 6 deletions

View File

@ -246,9 +246,11 @@ class DataSourceManager extends EventEmitter {
const ds = this.get(dsId);
if (!ds) return nodes;
const inEditor = this.app.platform === 'editor';
const ctxData = createIteratorContentData(itemData, ds.id, keys, this.data);
const { deps = {}, condDeps = {} } = getDeps(ds.schema, nodes);
const { deps = {}, condDeps = {} } = getDeps(ds.schema, nodes, inEditor);
if (!Object.keys(deps).length && !Object.keys(condDeps).length) {
return nodes;
@ -261,7 +263,7 @@ class DataSourceManager extends EventEmitter {
item,
deps,
condDeps,
inEditor: this.app.platform === 'editor',
inEditor,
ctxData,
}),
);

View File

@ -1,10 +1,30 @@
import type { DataSourceSchema, MNode } from '@tmagic/core';
import { DSL_NODE_KEY_COPY_PREFIX, isDataSourceCondTarget, isDataSourceTarget, Target, Watcher } from '@tmagic/core';
import type { DataSourceSchema, Id, MNode } from '@tmagic/core';
import {
DSL_NODE_KEY_COPY_PREFIX,
isDataSourceCondTarget,
isDataSourceTarget,
Target,
traverseNode,
Watcher,
} from '@tmagic/core';
const cache = new Map();
export const getDeps = (ds: DataSourceSchema, nodes: MNode[]) => {
const cacheKey = `${ds.id}:${nodes.map((node) => node.id).join(':')}`;
export const getDeps = (ds: DataSourceSchema, nodes: MNode[], inEditor: boolean) => {
let cacheKey: string;
if (inEditor) {
const ids: Id[] = [];
nodes.forEach((node) => {
traverseNode(node, (node) => {
ids.push(node.id);
});
});
cacheKey = `${ds.id}:${ids.join(':')}`;
} else {
cacheKey = `${ds.id}:${nodes.map((node) => node.id).join(':')}`;
}
if (cache.has(cacheKey)) {
return cache.get(cacheKey);