update(store): only inject if in current instance

Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
Braks
2021-12-04 15:42:18 +01:00
parent 0816bf0c75
commit bf9ce37b64
2 changed files with 14 additions and 12 deletions
+5 -3
View File
@@ -1,3 +1,4 @@
import { getCurrentInstance } from 'vue'
import { FlowExportObject, FlowOptions, FlowState, FlowStore } from '~/types'
import { useNewStore } from '~/store'
import { StoreSymbol } from '~/context'
@@ -36,11 +37,12 @@ export const createStore = (options?: FlowOptions) => {
}
export default (options?: FlowOptions): FlowStore => {
let store = options?.id ? createStore(options) : inject(StoreSymbol, undefined)
if (!store) {
const currentInstance = getCurrentInstance()
let store = currentInstance ? inject(StoreSymbol, undefined) : false
if (!store || (store && options?.id && options.id !== store.id?.value)) {
store = createStore(options)
}
provide(StoreSymbol, store)
if (currentInstance) provide(StoreSymbol, store)
return reactive(store)
}