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:
braks
2022-07-27 22:49:00 +02:00
committed by Braks
parent 73bf4db829
commit d62c3304e3
2 changed files with 13 additions and 8 deletions
@@ -93,6 +93,8 @@ export default (options?: FlowProps): VueFlowStore => {
let vueFlow: Injection
let isParentScope = false
/**
* check if we can get a store instance through injections
* this should be the regular way after initialization
@@ -122,6 +124,7 @@ export default (options?: FlowProps): VueFlowStore => {
if (scope) {
scope.vueFlowId = name
isParentScope = true
}
} else {
// 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) {
provide(VueFlow, vueFlow)
// dispose of state values and storage entry
tryOnScopeDispose(() => {
if (storage.get(vueFlow!.id)) {
storage.remove(vueFlow!.id)
}
vueFlow = null
})
if (isParentScope) {
// dispose of state values and storage entry
tryOnScopeDispose(() => {
if (storage.get(vueFlow!.id)) {
vueFlow!.$destroy()
}
vueFlow = null
})
}
}
return vueFlow
@@ -121,7 +121,6 @@ const el = ref<HTMLDivElement>()
onUnmounted(() => {
dispose()
$reset()
})
onMounted(() => {