Skip to content

Commit

Permalink
chore: fix reference
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Dec 16, 2022
1 parent 5df0ab6 commit 130ce09
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions packages/shared/createEventHook/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* The source code for this function was inspired by vue-apollo's `useEventHook` util
* https://github.com/vuejs/vue-apollo/blob/v4/packages/vue-apollo-composable/src/util/useEventHook.ts
*/
import { tryOnScopeDispose } from '@vueuse/core'
import { tryOnScopeDispose } from '../tryOnScopeDispose'

export type EventHookOn<T = any> = (fn: (param: T) => void) => { off: () => void }
export type EventHookOff<T = any> = (fn: (param: T) => void) => void
Expand Down Expand Up @@ -30,13 +30,12 @@ export function createEventHook<T = any>(): EventHook<T> {

const on = (fn: (param: T) => void) => {
fns.push(fn)
const offFn = () => off(fn)

tryOnScopeDispose(() => {
off(fn)
})
tryOnScopeDispose(offFn)

return {
off: () => off(fn),
off: offFn,
}
}

Expand Down

0 comments on commit 130ce09

Please sign in to comment.