feat: Add emits property to store

# What's changed?

* For easier access (and shorter syntax) of event emitters add emits property to store
* Change instance, zoom, hooks, emits and onEvent triggers to readonly
This commit is contained in:
Braks
2022-04-24 13:34:22 +02:00
parent c6840a31ad
commit f5d245322b
12 changed files with 103 additions and 76 deletions
+10 -4
View File
@@ -1,6 +1,6 @@
import { EffectScope } from 'vue'
import { MaybeRef } from '@vueuse/core'
import { FlowHooksOn, FlowOptions, FlowProps, State, VueFlowStore } from '~/types'
import { FlowOptions, FlowProps, State, VueFlowStore } from '~/types'
import { VueFlow } from '~/context'
import useState from '~/store/state'
import useGetters from '~/store/getters'
@@ -43,10 +43,15 @@ export class Storage {
const actions = useActions(reactiveState, getters)
const hooksOn: FlowHooksOn = <any>{}
const hooksOn = <any>{}
Object.entries(reactiveState.hooks).forEach(([n, h]) => {
const name = `on${n.charAt(0).toUpperCase() + n.slice(1)}` as keyof FlowHooksOn
hooksOn[name] = h.on as any
const name = `on${n.charAt(0).toUpperCase() + n.slice(1)}`
hooksOn[name] = h.on
})
const emits = <any>{}
Object.entries(reactiveState.hooks).forEach(([n, h]) => {
emits[n] = h.trigger
})
actions.setState(reactiveState)
@@ -61,6 +66,7 @@ export class Storage {
...getters,
...actions,
...toRefs(reactiveState),
emits,
id,
}