fix(hippy-react): support to emit multi parameters for HippyEvent

This commit is contained in:
zoomchan-cxj
2022-09-14 10:43:06 +08:00
committed by Zoom Chan
parent 4f88ad20f7
commit ddfbf75a1e
2 changed files with 5 additions and 5 deletions
@@ -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);
}
});
}