fix(core): ensure events introduced by the watcher are released when no longer needed

This commit is contained in:
jayrchamp
2023-10-30 13:36:07 +01:00
committed by Braks
parent 53be29de8a
commit 8651019eb6
+6 -1
View File
@@ -134,7 +134,7 @@ export function useVueFlow(options?: FlowProps): VueFlowStore {
detachedScope.run(() => {
watch(
state.applyDefault,
(shouldApplyDefault) => {
(shouldApplyDefault, __, onCleanup) => {
const nodesChangeHandler = (changes: NodeChange[]) => {
state.applyNodeChanges(changes)
}
@@ -150,6 +150,11 @@ export function useVueFlow(options?: FlowProps): VueFlowStore {
state.hooks.value.nodesChange.off(nodesChangeHandler)
state.hooks.value.edgesChange.off(edgesChangeHandler)
}
onCleanup(() => {
state.hooks.value.nodesChange.off(nodesChangeHandler)
state.hooks.value.edgesChange.off(edgesChangeHandler)
})
},
{ immediate: true },
)