feat(store): add store as refs to useVueFlow
Signed-off-by: Braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user