Skip to content

Commit

Permalink
fix(editor): 新增数据源方法不会收集依赖
Browse files Browse the repository at this point in the history
roymondchen committed Dec 8, 2023
1 parent cc202d7 commit fe26ac5
Showing 2 changed files with 21 additions and 11 deletions.
20 changes: 15 additions & 5 deletions packages/editor/src/initService.ts
Original file line number Diff line number Diff line change
@@ -291,7 +291,7 @@ export const initServiceEvents = (
depService.addTarget(createCodeBlockTarget(id, code));
});

value.dataSources.forEach((ds) => {
dataSourceService.get('dataSources').forEach((ds) => {
initDataSourceDepTarget(ds);
});

@@ -350,16 +350,16 @@ export const initServiceEvents = (
editorService.on('update', nodeUpdateHandler);

const codeBlockAddOrUpdateHandler = (id: Id, codeBlock: CodeBlockContent) => {
if (depService.hasTarget(id)) {
depService.getTarget(id)!.name = codeBlock.name;
if (depService.hasTarget(id, DepTargetType.CODE_BLOCK)) {
depService.getTarget(id, DepTargetType.CODE_BLOCK)!.name = codeBlock.name;
return;
}

depService.addTarget(createCodeBlockTarget(id, codeBlock));
};

const codeBlockRemoveHandler = (id: Id) => {
depService.removeTarget(id);
depService.removeTarget(id, DepTargetType.CODE_BLOCK);
};

codeBlockService.on('addOrUpdate', codeBlockAddOrUpdateHandler);
@@ -372,6 +372,10 @@ export const initServiceEvents = (

const dataSourceUpdateHandler = (config: DataSourceSchema) => {
const root = editorService.get('root');
removeDataSourceTarget(config.id);
initDataSourceDepTarget(config);

depService.collect(root?.items || [], true);

const targets = depService.getTargets(DepTargetType.DATA_SOURCE);

@@ -380,8 +384,14 @@ export const initServiceEvents = (
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) => {
depService.removeTarget(id);
removeDataSourceTarget(id);
getApp()?.dataSourceManager?.removeDataSource(id);
};

12 changes: 6 additions & 6 deletions packages/editor/src/services/dep.ts
Original file line number Diff line number Diff line change
@@ -35,17 +35,17 @@ class Dep extends BaseService {
return this.watcher.getTargets(type);
}

public getTarget(id: Id) {
return this.watcher.getTarget(id);
public getTarget(id: Id, type: string = DepTargetType.DEFAULT) {
return this.watcher.getTarget(id, type);
}

public addTarget(target: Target) {
this.watcher.addTarget(target);
this.emit('add-target', target);
}

public removeTarget(id: Id) {
this.watcher.removeTarget(id);
public removeTarget(id: Id, type: string = DepTargetType.DEFAULT) {
this.watcher.removeTarget(id, type);
this.emit('remove-target');
}

@@ -62,8 +62,8 @@ class Dep extends BaseService {
return this.watcher.clear(nodes);
}

public hasTarget(id: Id) {
return this.watcher.hasTarget(id);
public hasTarget(id: Id, type: string = DepTargetType.DEFAULT) {
return this.watcher.hasTarget(id, type);
}
}

0 comments on commit fe26ac5

Please sign in to comment.