feat(flow): Add event listener to vueflow object

* event listener also exist in store state (hooksOn)
* add applyChangesHandlers to vueflow object, can be used to apply changes i.e. deleting etc.

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 a604dd8ab1
commit d875cfede3
5 changed files with 54 additions and 10 deletions
+7 -1
View File
@@ -2,7 +2,7 @@ import { getCurrentInstance } from 'vue'
import useState, { initialState } from './state'
import useActions from './actions'
import useGetters from './getters'
import { FlowExportObject, FlowOptions, FlowState, FlowStore, Store } from '~/types'
import { FlowExportObject, FlowHooksOn, FlowOptions, FlowState, FlowStore, Store } from '~/types'
import { StoreSymbol } from '~/context'
import { onLoadToObject } from '~/utils'
@@ -10,9 +10,15 @@ const useFlowStore = (id: string, preloadedState: FlowState): Store => {
const state = reactive(useState(preloadedState))
const getters = useGetters(state)
const actions = useActions(state, getters)
const hooksOn: FlowHooksOn = <any>{}
Object.entries(state.hooks).forEach(([n, h]) => {
const name = `On${n.charAt(0).toUpperCase() + n.slice(1)}`
hooksOn[<keyof FlowHooksOn>name] = h.on as any
})
return {
id,
state,
hooksOn,
...toRefs(state),
...getters,
...actions,