mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-04-06 03:57:56 +08:00
fix(editor): 新增数据源方法不会收集依赖
This commit is contained in:
parent
cc202d79f9
commit
fe26ac5ffc
@ -291,7 +291,7 @@ export const initServiceEvents = (
|
|||||||
depService.addTarget(createCodeBlockTarget(id, code));
|
depService.addTarget(createCodeBlockTarget(id, code));
|
||||||
});
|
});
|
||||||
|
|
||||||
value.dataSources.forEach((ds) => {
|
dataSourceService.get('dataSources').forEach((ds) => {
|
||||||
initDataSourceDepTarget(ds);
|
initDataSourceDepTarget(ds);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -350,8 +350,8 @@ export const initServiceEvents = (
|
|||||||
editorService.on('update', nodeUpdateHandler);
|
editorService.on('update', nodeUpdateHandler);
|
||||||
|
|
||||||
const codeBlockAddOrUpdateHandler = (id: Id, codeBlock: CodeBlockContent) => {
|
const codeBlockAddOrUpdateHandler = (id: Id, codeBlock: CodeBlockContent) => {
|
||||||
if (depService.hasTarget(id)) {
|
if (depService.hasTarget(id, DepTargetType.CODE_BLOCK)) {
|
||||||
depService.getTarget(id)!.name = codeBlock.name;
|
depService.getTarget(id, DepTargetType.CODE_BLOCK)!.name = codeBlock.name;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -359,7 +359,7 @@ export const initServiceEvents = (
|
|||||||
};
|
};
|
||||||
|
|
||||||
const codeBlockRemoveHandler = (id: Id) => {
|
const codeBlockRemoveHandler = (id: Id) => {
|
||||||
depService.removeTarget(id);
|
depService.removeTarget(id, DepTargetType.CODE_BLOCK);
|
||||||
};
|
};
|
||||||
|
|
||||||
codeBlockService.on('addOrUpdate', codeBlockAddOrUpdateHandler);
|
codeBlockService.on('addOrUpdate', codeBlockAddOrUpdateHandler);
|
||||||
@ -372,6 +372,10 @@ export const initServiceEvents = (
|
|||||||
|
|
||||||
const dataSourceUpdateHandler = (config: DataSourceSchema) => {
|
const dataSourceUpdateHandler = (config: DataSourceSchema) => {
|
||||||
const root = editorService.get('root');
|
const root = editorService.get('root');
|
||||||
|
removeDataSourceTarget(config.id);
|
||||||
|
initDataSourceDepTarget(config);
|
||||||
|
|
||||||
|
depService.collect(root?.items || [], true);
|
||||||
|
|
||||||
const targets = depService.getTargets(DepTargetType.DATA_SOURCE);
|
const targets = depService.getTargets(DepTargetType.DATA_SOURCE);
|
||||||
|
|
||||||
@ -380,8 +384,14 @@ export const initServiceEvents = (
|
|||||||
upateNodeWhenDataSourceChange(nodes);
|
upateNodeWhenDataSourceChange(nodes);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const removeDataSourceTarget = (id: string) => {
|
||||||
|
depService.removeTarget(id, DepTargetType.DATA_SOURCE);
|
||||||
|
depService.removeTarget(id, DepTargetType.DATA_SOURCE_COND);
|
||||||
|
depService.removeTarget(id, DepTargetType.DATA_SOURCE_METHOD);
|
||||||
|
};
|
||||||
|
|
||||||
const dataSourceRemoveHandler = (id: string) => {
|
const dataSourceRemoveHandler = (id: string) => {
|
||||||
depService.removeTarget(id);
|
removeDataSourceTarget(id);
|
||||||
getApp()?.dataSourceManager?.removeDataSource(id);
|
getApp()?.dataSourceManager?.removeDataSource(id);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -35,8 +35,8 @@ class Dep extends BaseService {
|
|||||||
return this.watcher.getTargets(type);
|
return this.watcher.getTargets(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public getTarget(id: Id) {
|
public getTarget(id: Id, type: string = DepTargetType.DEFAULT) {
|
||||||
return this.watcher.getTarget(id);
|
return this.watcher.getTarget(id, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public addTarget(target: Target) {
|
public addTarget(target: Target) {
|
||||||
@ -44,8 +44,8 @@ class Dep extends BaseService {
|
|||||||
this.emit('add-target', target);
|
this.emit('add-target', target);
|
||||||
}
|
}
|
||||||
|
|
||||||
public removeTarget(id: Id) {
|
public removeTarget(id: Id, type: string = DepTargetType.DEFAULT) {
|
||||||
this.watcher.removeTarget(id);
|
this.watcher.removeTarget(id, type);
|
||||||
this.emit('remove-target');
|
this.emit('remove-target');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,8 +62,8 @@ class Dep extends BaseService {
|
|||||||
return this.watcher.clear(nodes);
|
return this.watcher.clear(nodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public hasTarget(id: Id) {
|
public hasTarget(id: Id, type: string = DepTargetType.DEFAULT) {
|
||||||
return this.watcher.hasTarget(id);
|
return this.watcher.hasTarget(id, type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user