fix(store): only run scope dispose on parent caller
# What's changed?
* Only run scope disposal on parent scopes
* the uppermost `useVueFlow` call
* Do not reset store on flow unmount
* Fixes issue that flow is broken after a `v-if` toggle
This commit is contained in:
@@ -93,6 +93,8 @@ export default (options?: FlowProps): VueFlowStore => {
|
|||||||
|
|
||||||
let vueFlow: Injection
|
let vueFlow: Injection
|
||||||
|
|
||||||
|
let isParentScope = false
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* check if we can get a store instance through injections
|
* check if we can get a store instance through injections
|
||||||
* this should be the regular way after initialization
|
* this should be the regular way after initialization
|
||||||
@@ -122,6 +124,7 @@ export default (options?: FlowProps): VueFlowStore => {
|
|||||||
|
|
||||||
if (scope) {
|
if (scope) {
|
||||||
scope.vueFlowId = name
|
scope.vueFlowId = name
|
||||||
|
isParentScope = true
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// if composable was called with additional options after initialization, overwrite state with the options values
|
// if composable was called with additional options after initialization, overwrite state with the options values
|
||||||
@@ -137,13 +140,16 @@ export default (options?: FlowProps): VueFlowStore => {
|
|||||||
if (scope) {
|
if (scope) {
|
||||||
provide(VueFlow, vueFlow)
|
provide(VueFlow, vueFlow)
|
||||||
|
|
||||||
// dispose of state values and storage entry
|
if (isParentScope) {
|
||||||
tryOnScopeDispose(() => {
|
// dispose of state values and storage entry
|
||||||
if (storage.get(vueFlow!.id)) {
|
tryOnScopeDispose(() => {
|
||||||
storage.remove(vueFlow!.id)
|
if (storage.get(vueFlow!.id)) {
|
||||||
}
|
vueFlow!.$destroy()
|
||||||
vueFlow = null
|
}
|
||||||
})
|
|
||||||
|
vueFlow = null
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return vueFlow
|
return vueFlow
|
||||||
|
|||||||
@@ -121,7 +121,6 @@ const el = ref<HTMLDivElement>()
|
|||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
dispose()
|
dispose()
|
||||||
$reset()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user