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 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(() => {