fix(flow): computed getter type
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import useState from './state'
|
||||
import { ComputedGetters } from './getters'
|
||||
import {
|
||||
Actions,
|
||||
Connection,
|
||||
@@ -14,6 +13,7 @@ import {
|
||||
NodeDimensionChange,
|
||||
NodePositionChange,
|
||||
State,
|
||||
ComputedGetters,
|
||||
} from '~/types'
|
||||
import {
|
||||
applyNodeChanges as applyNodes,
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
import { ComputedRef } from 'vue'
|
||||
import { defaultEdgeTypes, defaultNodeTypes } from './state'
|
||||
import { State, GraphEdge, GraphNode, Getters } from '~/types'
|
||||
import { State, GraphEdge, GraphNode, ComputedGetters } from '~/types'
|
||||
import { getNodesInside, isEdgeVisible } from '~/utils'
|
||||
|
||||
export type ComputedGetters<N = any, E = N> = { [key in keyof Getters<N, E>]: ComputedRef<Getters<N, E>[key]> }
|
||||
|
||||
export default (state: State): ComputedGetters => {
|
||||
const getEdgeTypes = computed(() => {
|
||||
const edgeTypes: Record<string, any> = {
|
||||
@@ -27,7 +24,7 @@ export default (state: State): ComputedGetters => {
|
||||
})
|
||||
|
||||
const getNodes = computed<GraphNode[]>(() => {
|
||||
if (state.paneReady && state.dimensions.width && state.dimensions.height) {
|
||||
if (state.paneReady) {
|
||||
const nodes = state.nodes.filter((n) => !n.hidden)
|
||||
return state.onlyRenderVisibleElements
|
||||
? nodes &&
|
||||
@@ -48,7 +45,7 @@ export default (state: State): ComputedGetters => {
|
||||
})
|
||||
|
||||
const getEdges = computed<GraphEdge[]>(() => {
|
||||
if (state.paneReady && state.dimensions.width && state.dimensions.height) {
|
||||
if (state.paneReady) {
|
||||
if (!state.onlyRenderVisibleElements)
|
||||
return state.edges.filter(
|
||||
(e) => !e.hidden && e.targetNode && !e.targetNode.hidden && e.sourceNode && !e.sourceNode.hidden,
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
export { default as useHooks, createHooks } from './hooks'
|
||||
export { default as useStore } from './store'
|
||||
export * from './actions'
|
||||
export * from './state'
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
import useState from './state'
|
||||
import useActions from './actions'
|
||||
import useGetters from './getters'
|
||||
import { FlowHooksOn, FlowOptions, Store, State } from '~/types'
|
||||
|
||||
export default (preloadedState?: FlowOptions): Store => {
|
||||
const state: State = useState(preloadedState)
|
||||
const reactiveState = reactive(state)
|
||||
const getters = useGetters(reactiveState)
|
||||
const actions = useActions(reactiveState, getters)
|
||||
const hooksOn: FlowHooksOn = <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
|
||||
})
|
||||
actions.setState(reactiveState)
|
||||
if (preloadedState) {
|
||||
if (preloadedState.modelValue) actions.setElements(preloadedState.modelValue)
|
||||
if (preloadedState.nodes) actions.setNodes(preloadedState.nodes)
|
||||
if (preloadedState.edges) actions.setEdges(preloadedState.edges)
|
||||
}
|
||||
|
||||
return reactive({
|
||||
state: reactiveState,
|
||||
...hooksOn,
|
||||
...toRefs(reactiveState),
|
||||
...getters,
|
||||
...actions,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user