feat(store, flow)!: Add apply changes handlers

* flow will not update changes unless a handler to apply changes is passed
* a default handler is available in the useVueFlow composable
* removeElements export removed
This commit is contained in:
Braks
2021-12-20 19:29:52 +01:00
parent f6007d026c
commit 81c8145f3a
19 changed files with 173 additions and 184 deletions
+8 -1
View File
@@ -2,9 +2,10 @@ import { getCurrentInstance } from 'vue'
import useState, { initialState } from './state'
import useActions from './actions'
import useGetters from './getters'
import { FlowExportObject, FlowHooksOn, FlowOptions, FlowState, FlowStore, Store } from '~/types'
import { EmitFunc, FlowExportObject, FlowHooksOn, FlowOptions, FlowState, FlowStore, Store } from '~/types'
import { StoreSymbol } from '~/context'
import { onLoadToObject } from '~/utils'
import { useHooks, useStore } from '~/store/index'
const useFlowStore = (id: string, preloadedState: FlowState): Store => {
const state = reactive(useState(preloadedState))
@@ -61,6 +62,12 @@ export const createStore = (options?: FlowOptions) => {
return store
}
export const initFlow = (emit: EmitFunc, id?: string): FlowStore => {
const store = useStore({ id })
useHooks(store, emit)
return store
}
export default (options?: FlowOptions): FlowStore => {
const currentInstance = getCurrentInstance()
let store = currentInstance ? inject(StoreSymbol, undefined) : false