fix(store): correct injection and remove id from refs
Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { getCurrentInstance } from 'vue'
|
import { getCurrentInstance } from 'vue'
|
||||||
import { FlowExportObject, FlowOptions, FlowState, FlowStore } from '~/types'
|
import { FlowExportObject, FlowOptions, FlowState, FlowStore } from '~/types'
|
||||||
import { useNewStore } from '~/store'
|
import { useFlowStore } from '~/store'
|
||||||
import { StoreSymbol } from '~/context'
|
import { StoreSymbol } from '~/context'
|
||||||
import { onLoadToObject, initialState } from '~/utils'
|
import { onLoadToObject, initialState } from '~/utils'
|
||||||
|
|
||||||
@@ -10,6 +10,7 @@ export const createStore = (options?: FlowOptions) => {
|
|||||||
let storedState = ref<FlowExportObject>()
|
let storedState = ref<FlowExportObject>()
|
||||||
const initial = initialState()
|
const initial = initialState()
|
||||||
const storageKey = options?.id ?? `vue-flow-${id++}`
|
const storageKey = options?.id ?? `vue-flow-${id++}`
|
||||||
|
delete options?.id
|
||||||
const preloadedState = {
|
const preloadedState = {
|
||||||
...initial,
|
...initial,
|
||||||
...(options as FlowState),
|
...(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]
|
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) {
|
if (withStorage && storageKey === store.id) {
|
||||||
const toObject = onLoadToObject(store.state)
|
const toObject = onLoadToObject(store.state)
|
||||||
watch(
|
watch(
|
||||||
|
|||||||
@@ -2,8 +2,7 @@ import useStore from './useStore'
|
|||||||
import useHooks from './useHooks'
|
import useHooks from './useHooks'
|
||||||
import { EmitFunc, FlowStore } from '~/types'
|
import { EmitFunc, FlowStore } from '~/types'
|
||||||
|
|
||||||
let key = 0
|
export const initFlow = (emit: EmitFunc, id?: string): FlowStore => {
|
||||||
export const initFlow = (emit: EmitFunc, id = `vue-flow-${key++}`): FlowStore => {
|
|
||||||
const store = useStore({ id })
|
const store = useStore({ id })
|
||||||
useHooks(store, emit)
|
useHooks(store, emit)
|
||||||
return store
|
return store
|
||||||
|
|||||||
+1
-1
@@ -1 +1 @@
|
|||||||
export { default as useNewStore } from './store'
|
export { default as useFlowStore } from './store'
|
||||||
|
|||||||
+1
-1
@@ -97,7 +97,7 @@ const connectionExists = (edge: Edge, elements: Elements) => {
|
|||||||
|
|
||||||
export const addEdge = (edgeParams: Edge | Connection, elements: Elements) => {
|
export const addEdge = (edgeParams: Edge | Connection, elements: Elements) => {
|
||||||
if (!edgeParams.source || !edgeParams.target) {
|
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
|
return elements
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user