refactor(flow): set elements when initializing store
Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { getCurrentInstance } from 'vue'
|
import { getCurrentInstance } from 'vue'
|
||||||
import { FlowOptions, State, UseVueFlow } from '~/types'
|
import { FlowOptions, UseVueFlow } from '~/types'
|
||||||
import { VueFlow } from '~/context'
|
import { VueFlow } from '~/context'
|
||||||
import { useStore } from '~/store'
|
import { useStore } from '~/store'
|
||||||
|
|
||||||
@@ -11,7 +11,7 @@ export default (options?: Partial<FlowOptions>): UseVueFlow => {
|
|||||||
: false
|
: false
|
||||||
if (!vueFlow || (vueFlow && options?.id && options.id !== vueFlow.id)) {
|
if (!vueFlow || (vueFlow && options?.id && options.id !== vueFlow.id)) {
|
||||||
const name = options?.id ?? `vue-flow-${id++}`
|
const name = options?.id ?? `vue-flow-${id++}`
|
||||||
const store = useStore(options as State)
|
const store = useStore(options)
|
||||||
vueFlow = {
|
vueFlow = {
|
||||||
id: name,
|
id: name,
|
||||||
store: reactive(store),
|
store: reactive(store),
|
||||||
|
|||||||
+7
-2
@@ -1,9 +1,9 @@
|
|||||||
import useState from './state'
|
import useState from './state'
|
||||||
import useActions from './actions'
|
import useActions from './actions'
|
||||||
import useGetters from './getters'
|
import useGetters from './getters'
|
||||||
import { FlowHooksOn, State, Store } from '~/types'
|
import { FlowHooksOn, FlowOptions, Store } from '~/types'
|
||||||
|
|
||||||
export default (preloadedState: State): Store => {
|
export default (preloadedState?: FlowOptions): Store => {
|
||||||
const state = reactive(useState(preloadedState))
|
const state = reactive(useState(preloadedState))
|
||||||
const getters = useGetters(state)
|
const getters = useGetters(state)
|
||||||
const actions = useActions(state, getters)
|
const actions = useActions(state, getters)
|
||||||
@@ -13,6 +13,11 @@ export default (preloadedState: State): Store => {
|
|||||||
hooksOn[<keyof FlowHooksOn>name] = h.on as any
|
hooksOn[<keyof FlowHooksOn>name] = h.on as any
|
||||||
})
|
})
|
||||||
actions.setState(state)
|
actions.setState(state)
|
||||||
|
if (preloadedState) {
|
||||||
|
if (preloadedState.modelValue) actions.setElements(preloadedState.modelValue)
|
||||||
|
if (preloadedState.nodes) actions.setNodes(preloadedState.nodes)
|
||||||
|
if (preloadedState.edges) actions.setEdges(preloadedState.edges)
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
state,
|
state,
|
||||||
|
|||||||
Reference in New Issue
Block a user