fix(core): push emit handlers into listeners set

This commit is contained in:
braks
2023-10-27 19:39:54 +02:00
committed by Braks
parent 0bf12601df
commit 2ecd8def81
2 changed files with 4 additions and 1 deletions

View File

@@ -69,7 +69,8 @@ export function useHooks(emit: (...args: any[]) => void, hooks: Ref<FlowHooks>)
emit(key, data)
}
value.on(listener)
// push into fns instead of using `on` to avoid overwriting default handlers - the emits should be called in addition to the default handlers
value.fns.add(listener)
tryOnScopeDispose(() => {
value.off(listener)

View File

@@ -8,6 +8,7 @@ import { tryOnScopeDispose } from '@vueuse/core'
*/
export interface EventHookExtended<T> extends EventHook<T> {
hasListeners: () => boolean
fns: Set<(param: T) => void>
}
export function createExtendedEventHook<T = any>(defaultHandler?: (param: T) => void): EventHookExtended<T> {
@@ -50,5 +51,6 @@ export function createExtendedEventHook<T = any>(defaultHandler?: (param: T) =>
off,
trigger,
hasListeners,
fns,
}
}