update(store): only inject if in current instance
Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import { getCurrentInstance } from 'vue'
|
||||||
import { FlowExportObject, FlowOptions, FlowState, FlowStore } from '~/types'
|
import { FlowExportObject, FlowOptions, FlowState, FlowStore } from '~/types'
|
||||||
import { useNewStore } from '~/store'
|
import { useNewStore } from '~/store'
|
||||||
import { StoreSymbol } from '~/context'
|
import { StoreSymbol } from '~/context'
|
||||||
@@ -36,11 +37,12 @@ export const createStore = (options?: FlowOptions) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default (options?: FlowOptions): FlowStore => {
|
export default (options?: FlowOptions): FlowStore => {
|
||||||
let store = options?.id ? createStore(options) : inject(StoreSymbol, undefined)
|
const currentInstance = getCurrentInstance()
|
||||||
if (!store) {
|
let store = currentInstance ? inject(StoreSymbol, undefined) : false
|
||||||
|
if (!store || (store && options?.id && options.id !== store.id?.value)) {
|
||||||
store = createStore(options)
|
store = createStore(options)
|
||||||
}
|
}
|
||||||
provide(StoreSymbol, store)
|
if (currentInstance) provide(StoreSymbol, store)
|
||||||
|
|
||||||
return reactive(store)
|
return reactive(store)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -146,10 +146,14 @@ const transitionName = computed(() => {
|
|||||||
return name
|
return name
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
<script lang="ts">
|
||||||
|
export default {
|
||||||
|
name: 'VueFlow',
|
||||||
|
}
|
||||||
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<div class="vue-flow">
|
<div class="vue-flow">
|
||||||
<Transition :key="`vue-flow-transition-${store.id}`" :name="transitionName">
|
<Transition :name="transitionName">
|
||||||
<Suspense timeout="0">
|
<Suspense timeout="0">
|
||||||
<template #default>
|
<template #default>
|
||||||
<Renderer :key="`renderer-${store.id}`" :elements="elements">
|
<Renderer :key="`renderer-${store.id}`" :elements="elements">
|
||||||
@@ -230,11 +234,7 @@ const transitionName = computed(() => {
|
|||||||
<slot :name="`edge-${edgeName}`" v-bind="edgeProps" />
|
<slot :name="`edge-${edgeName}`" v-bind="edgeProps" />
|
||||||
</template>
|
</template>
|
||||||
<template #custom-connection-line="customConnectionLineProps">
|
<template #custom-connection-line="customConnectionLineProps">
|
||||||
<slot
|
<slot name="custom-connection-line" v-bind="customConnectionLineProps" />
|
||||||
:key="`connection-line-${store.id}`"
|
|
||||||
name="custom-connection-line"
|
|
||||||
v-bind="customConnectionLineProps"
|
|
||||||
/>
|
|
||||||
</template>
|
</template>
|
||||||
</EdgeRenderer>
|
</EdgeRenderer>
|
||||||
</SelectionPane>
|
</SelectionPane>
|
||||||
@@ -244,8 +244,8 @@ const transitionName = computed(() => {
|
|||||||
</Renderer>
|
</Renderer>
|
||||||
</template>
|
</template>
|
||||||
<template v-if="store.loading" #fallback>
|
<template v-if="store.loading" #fallback>
|
||||||
<slot :key="`loading-indicator-${store.id}`" name="loading-indicator">
|
<slot name="loading-indicator">
|
||||||
<LoadingIndicator :key="`default-loading-indicator-${store.id}`" v-bind="store.loading">
|
<LoadingIndicator v-bind="store.loading">
|
||||||
<slot name="loading-label" />
|
<slot name="loading-label" />
|
||||||
</LoadingIndicator>
|
</LoadingIndicator>
|
||||||
</slot>
|
</slot>
|
||||||
|
|||||||
Reference in New Issue
Block a user