mirror of
https://github.com/Tencent/Hippy.git
synced 2026-10-29 06:06:52 +08:00
fix(hippy-react): support to emit multi parameters for HippyEvent
This commit is contained in:
@@ -110,7 +110,7 @@ const HippyEvent = {
|
||||
}
|
||||
return 0;
|
||||
},
|
||||
emit(event: string | undefined, param?: any) {
|
||||
emit(event: string | undefined, ...param: any) {
|
||||
if (typeof event !== 'string') {
|
||||
throw new TypeError('The event argument is not string for HippyEvent.emit()');
|
||||
}
|
||||
@@ -119,7 +119,7 @@ const HippyEvent = {
|
||||
warn(`Event [${event}] has not been registered yet in HippyEvent`);
|
||||
return HippyEvent;
|
||||
}
|
||||
eventHub.notifyEvent(param);
|
||||
eventHub.notifyEvent(...param);
|
||||
return HippyEvent;
|
||||
},
|
||||
};
|
||||
|
||||
@@ -63,16 +63,16 @@ class HippyEventHub implements HippyEventHub {
|
||||
return currId;
|
||||
}
|
||||
|
||||
public notifyEvent(eventParams: any) {
|
||||
public notifyEvent(...eventParams: any) {
|
||||
Object.keys(this.handlerContainer).forEach((key) => {
|
||||
const instance = this.handlerContainer[key];
|
||||
if (!instance || !instance.eventHandler) {
|
||||
return;
|
||||
}
|
||||
if (instance.context) {
|
||||
instance.eventHandler.call(instance.context, eventParams);
|
||||
instance.eventHandler.call(instance.context, ...eventParams);
|
||||
} else {
|
||||
instance.eventHandler(eventParams);
|
||||
instance.eventHandler(...eventParams);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user