fix(core): 多个组件配置同一事件会导致此事件多次监听

fix #356
This commit is contained in:
roymondchen 2022-09-20 15:20:42 +08:00 committed by jia000
parent 6d91cacc84
commit b835bb2488

View File

@ -28,6 +28,7 @@ import {
isCommonMethod,
triggerCommonMethod,
} from './events';
import type Node from './Node';
import Page from './Page';
import { fillBackgroundImage, isNumber, style2Obj } from './utils';
@ -207,11 +208,18 @@ class App extends EventEmitter {
eventName = getCommonEventName(eventName, id);
}
this.on(eventName, (fromCpt, ...args) => {
this.on(`${eventName}_${id}`, (fromCpt: Node, ...args) => {
this.eventHandler(event, fromCpt, args);
});
}
public emit(name: string | symbol, node: any, ...args: any[]): boolean {
if (typeof node.data === 'undefined') {
return super.emit(name, node, ...args);
}
return super.emit(`${String(name)}_${node.data.id}`, ...args);
}
public eventHandler(eventConfig: EventItemConfig, fromCpt: any, args: any[]) {
if (!this.page) throw new Error('当前没有页面');