Fix React scope event listener (#16434)

GitOrigin-RevId: 1846ad511f915ff48f2f20a8b8a7f1174bb21525
This commit is contained in:
Alf Eaton 2024-01-09 09:14:09 +00:00 committed by Copybot
parent 20bd57e9bd
commit 678f0eb498

View file

@ -14,12 +14,18 @@ export class ReactScopeEventEmitter implements ScopeEventEmitter {
on(eventName: ScopeEventName, listener: (...args: unknown[]) => void) {
// A listener attached via useScopeEventListener expects an event as the
// first parameter. We don't have one, so just provide an empty object
const wrappedListener = (...detail: unknown[]) => {
listener({}, ...detail)
const wrappedListener = (event: CustomEvent<unknown[]>) => {
listener({}, ...event.detail)
}
this.eventEmitter.addEventListener(eventName, wrappedListener)
this.eventEmitter.addEventListener(
eventName,
wrappedListener as EventListener
)
return () => {
this.eventEmitter.removeEventListener(eventName, wrappedListener)
this.eventEmitter.removeEventListener(
eventName,
wrappedListener as EventListener
)
}
}
}