feat(store): add store as refs to useVueFlow

Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
Braks
2021-12-20 19:29:52 +01:00
parent be725c6d2d
commit 91009e1dca
8 changed files with 46 additions and 29 deletions
+6 -3
View File
@@ -8,16 +8,19 @@ import { useStore } from '~/store'
const applyNodeChanges = (changes: NodeChange[], nodes: GraphNode[]) => applyChanges(changes, nodes)
const applyEdgeChanges = (changes: EdgeChange[], edges: GraphEdge[]) => applyChanges(changes, edges)
let id = 0
export default (options?: FlowOptions): UseVueFlow => {
const currentInstance = getCurrentInstance()
let vueFlow: UseVueFlow | false | undefined = currentInstance ? inject(VueFlow, undefined) : false
if (!vueFlow || (vueFlow && options?.id && options.id !== vueFlow.store.id)) {
const store = reactive(useStore(options))
if (!vueFlow || (vueFlow && options?.id && options.id !== vueFlow.id)) {
const name = options?.id ?? `vue-flow-${id++}`
const store = reactive(useStore(name, options))
const applyNodes = (changes: NodeChange[]) => applyNodeChanges(changes, store.nodes)
const applyEdges = (changes: EdgeChange[]) => applyEdgeChanges(changes, store.edges)
vueFlow = {
id: store.id,
id: name,
store,
...toRefs(store),
useNodesState: (nodes, applyDefault = true) => useNodesState(store, applyNodes)({ nodes, applyDefault }),
useEdgesState: (edges, applyDefault = true) => useEdgesState(store, applyEdges)({ edges, applyDefault }),
applyNodeChanges: applyNodes,