fix(store): cleanup default change handlers on watch scope dispose
This commit is contained in:
@@ -158,7 +158,7 @@ export default (models: ToRefs<Pick<FlowProps, 'nodes' | 'edges' | 'modelValue'>
|
|||||||
|
|
||||||
watch(
|
watch(
|
||||||
store.applyDefault,
|
store.applyDefault,
|
||||||
() => {
|
(_, __, onCleanup) => {
|
||||||
if (store.applyDefault.value) {
|
if (store.applyDefault.value) {
|
||||||
store.onNodesChange(store.applyNodeChanges)
|
store.onNodesChange(store.applyNodeChanges)
|
||||||
store.onEdgesChange(store.applyEdgeChanges)
|
store.onEdgesChange(store.applyEdgeChanges)
|
||||||
@@ -166,6 +166,11 @@ export default (models: ToRefs<Pick<FlowProps, 'nodes' | 'edges' | 'modelValue'>
|
|||||||
store.hooks.value.nodesChange.off(store.applyNodeChanges)
|
store.hooks.value.nodesChange.off(store.applyNodeChanges)
|
||||||
store.hooks.value.edgesChange.off(store.applyEdgeChanges)
|
store.hooks.value.edgesChange.off(store.applyEdgeChanges)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onCleanup(() => {
|
||||||
|
store.hooks.value.nodesChange.off(store.applyNodeChanges)
|
||||||
|
store.hooks.value.edgesChange.off(store.applyEdgeChanges)
|
||||||
|
})
|
||||||
},
|
},
|
||||||
{ immediate: true },
|
{ immediate: true },
|
||||||
)
|
)
|
||||||
@@ -198,12 +203,16 @@ export default (models: ToRefs<Pick<FlowProps, 'nodes' | 'edges' | 'modelValue'>
|
|||||||
|
|
||||||
watch(
|
watch(
|
||||||
store.autoConnect,
|
store.autoConnect,
|
||||||
(autoConnectEnabled) => {
|
(autoConnectEnabled, _, onCleanup) => {
|
||||||
if (autoConnectEnabled) {
|
if (autoConnectEnabled) {
|
||||||
store.onConnect(autoConnector)
|
store.onConnect(autoConnector)
|
||||||
} else {
|
} else {
|
||||||
store.hooks.value.connect.off(autoConnector)
|
store.hooks.value.connect.off(autoConnector)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onCleanup(() => {
|
||||||
|
store.hooks.value.connect.off(autoConnector)
|
||||||
|
})
|
||||||
},
|
},
|
||||||
{ immediate: true },
|
{ immediate: true },
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user