fix(store): correct injection and remove id from refs

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 491c83dcc8
commit 3b448100d6
4 changed files with 6 additions and 6 deletions
+3 -2
View File
@@ -1,6 +1,6 @@
import { getCurrentInstance } from 'vue'
import { FlowExportObject, FlowOptions, FlowState, FlowStore } from '~/types'
import { useNewStore } from '~/store'
import { useFlowStore } from '~/store'
import { StoreSymbol } from '~/context'
import { onLoadToObject, initialState } from '~/utils'
@@ -10,6 +10,7 @@ export const createStore = (options?: FlowOptions) => {
let storedState = ref<FlowExportObject>()
const initial = initialState()
const storageKey = options?.id ?? `vue-flow-${id++}`
delete options?.id
const preloadedState = {
...initial,
...(options as FlowState),
@@ -22,7 +23,7 @@ export const createStore = (options?: FlowOptions) => {
preloadedState.transform = [storedState.value.position[0], storedState.value.position[1], storedState.value.zoom]
}
}
const store = useNewStore(storageKey, preloadedState)
const store = useFlowStore(storageKey, preloadedState)
if (withStorage && storageKey === store.id) {
const toObject = onLoadToObject(store.state)
watch(
+1 -2
View File
@@ -2,8 +2,7 @@ import useStore from './useStore'
import useHooks from './useHooks'
import { EmitFunc, FlowStore } from '~/types'
let key = 0
export const initFlow = (emit: EmitFunc, id = `vue-flow-${key++}`): FlowStore => {
export const initFlow = (emit: EmitFunc, id?: string): FlowStore => {
const store = useStore({ id })
useHooks(store, emit)
return store
+1 -1
View File
@@ -1 +1 @@
export { default as useNewStore } from './store'
export { default as useFlowStore } from './store'
+1 -1
View File
@@ -97,7 +97,7 @@ const connectionExists = (edge: Edge, elements: Elements) => {
export const addEdge = (edgeParams: Edge | Connection, elements: Elements) => {
if (!edgeParams.source || !edgeParams.target) {
console.log("Can't create edge. An edge needs a source and a target.")
console.warn("Can't create edge. An edge needs a source and a target.")
return elements
}