Skip to content

Commit

Permalink
fix(editor): 编辑器组件销毁后重置依赖收集
Browse files Browse the repository at this point in the history
  • Loading branch information
roymondchen committed Jan 20, 2025
1 parent e234428 commit 51ca1e6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/editor/src/initService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const initServiceState = (
codeBlockService,
keybindingService,
dataSourceService,
depService,
}: Services,
) => {
// 初始值变化,重新设置节点信息
Expand Down Expand Up @@ -203,6 +204,7 @@ export const initServiceState = (
componentListService.resetState();
codeBlockService.resetState();
keybindingService.reset();
depService.reset();
});
};

Expand Down
17 changes: 17 additions & 0 deletions packages/editor/src/services/dep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,23 @@ class Dep extends BaseService {
return super.once(eventName, listener as any);
}

public reset() {
idleTask.removeAllListeners();
idleTask.clearTasks();

for (const type of Object.keys(this.watcher.getTargetsList())) {
this.removeTargets(type);
}

this.set('collecting', false);
}

public destroy() {
this.removeAllListeners();
this.reset();
this.removeAllPlugins();
}

public emit<Name extends keyof DepEvents, Param extends DepEvents[Name]>(eventName: Name, ...args: Param) {
return super.emit(eventName, ...args);
}
Expand Down
1 change: 1 addition & 0 deletions packages/editor/src/utils/idle-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export class IdleTask<T = any> extends EventEmitter {

this.hightLevelTaskList = [];
this.taskList = [];
this.taskHandle = null;
}

public on<Name extends keyof IdleTaskEvents, Param extends IdleTaskEvents[Name]>(
Expand Down

0 comments on commit 51ca1e6

Please sign in to comment.