refactor(store): re-bind hooks on mount and use hooks ref
This commit is contained in:
@@ -127,7 +127,7 @@ onMounted(() => {
|
|||||||
vueFlowRef.value = el.value!
|
vueFlowRef.value = el.value!
|
||||||
})
|
})
|
||||||
|
|
||||||
useHooks(emit, hooks.value)
|
useHooks(emit, hooks)
|
||||||
|
|
||||||
provide(Slots, useSlots())
|
provide(Slots, useSlots())
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import type { Ref } from 'vue'
|
||||||
import type { Emits, FlowHooks } from '~/types'
|
import type { Emits, FlowHooks } from '~/types'
|
||||||
|
|
||||||
// flow event hooks
|
// flow event hooks
|
||||||
@@ -48,18 +49,18 @@ export const createHooks = (): FlowHooks => ({
|
|||||||
updateNodeInternals: createEventHook(),
|
updateNodeInternals: createEventHook(),
|
||||||
})
|
})
|
||||||
|
|
||||||
const bind = (emit: Emits, hooks: FlowHooks) => {
|
export default (emit: Emits, hooks: Ref<FlowHooks>) => {
|
||||||
for (const [key, value] of Object.entries(hooks)) {
|
onBeforeMount(() => {
|
||||||
const listener = (data: any) => {
|
for (const [key, value] of Object.entries(hooks.value)) {
|
||||||
emit(key as any, data)
|
const listener = (data: any) => {
|
||||||
|
emit(key as Emits extends (event: infer Event) => void ? Event : never, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
value.on(listener)
|
||||||
|
|
||||||
|
tryOnScopeDispose(() => {
|
||||||
|
value.off(listener)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
})
|
||||||
value.on(listener)
|
|
||||||
|
|
||||||
tryOnScopeDispose(() => {
|
|
||||||
value.off(listener)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default (emit: Emits, hooks: FlowHooks) => bind(emit, hooks)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user