mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-09-27 03:29:58 +08:00
fix(core): 一个组件配置多个相同的事件销毁后没有能成功移除事件绑定
This commit is contained in:
parent
d8d9184f3f
commit
47c26ed189
@ -78,7 +78,7 @@ class App extends EventEmitter {
|
|||||||
|
|
||||||
public eventQueueMap: Record<string, EventCache[]> = {};
|
public eventQueueMap: Record<string, EventCache[]> = {};
|
||||||
|
|
||||||
private eventList: { [name: string]: (fromCpt: Node, ...args: any[]) => void } = {};
|
private eventList = new Map<(fromCpt: Node, ...args: any[]) => void, string>();
|
||||||
|
|
||||||
constructor(options: AppOptionsConfig) {
|
constructor(options: AppOptionsConfig) {
|
||||||
super();
|
super();
|
||||||
@ -251,11 +251,12 @@ class App extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public bindEvents() {
|
public bindEvents() {
|
||||||
Object.entries(this.eventList).forEach(([name, handler]) => {
|
Array.from(this.eventList.keys()).forEach((handler) => {
|
||||||
this.off(name, handler);
|
const name = this.eventList.get(handler);
|
||||||
|
name && this.off(name, handler);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.eventList = {};
|
this.eventList.clear();
|
||||||
|
|
||||||
if (!this.page) return;
|
if (!this.page) return;
|
||||||
|
|
||||||
@ -265,8 +266,7 @@ class App extends EventEmitter {
|
|||||||
const eventHanlder = (fromCpt: Node, ...args: any[]) => {
|
const eventHanlder = (fromCpt: Node, ...args: any[]) => {
|
||||||
this.eventHandler(event, fromCpt, args);
|
this.eventHandler(event, fromCpt, args);
|
||||||
};
|
};
|
||||||
this.eventList[eventName] = eventHanlder;
|
this.eventList.set(eventHanlder, eventName);
|
||||||
|
|
||||||
this.on(eventName, eventHanlder);
|
this.on(eventName, eventHanlder);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user