fix: Return empty arrays if pane isn't ready yet

This commit is contained in:
Braks
2022-04-11 11:30:10 +02:00
parent 636598ba1a
commit ea69dc58ee
2 changed files with 9 additions and 0 deletions
+1
View File
@@ -53,6 +53,7 @@ export class Storage {
...getters, ...getters,
...actions, ...actions,
}) })
const flow: UseVueFlow = { const flow: UseVueFlow = {
...hooksOn, ...hooksOn,
...getters, ...getters,
+8
View File
@@ -3,6 +3,10 @@ import { State, GraphEdge, GraphNode, ComputedGetters } from '~/types'
import { getNodesInside, isEdgeVisible } from '~/utils' import { getNodesInside, isEdgeVisible } from '~/utils'
export default (state: State): ComputedGetters => { export default (state: State): ComputedGetters => {
const paneReady = ref(false)
state.hooks.paneReady.on(() => (paneReady.value = true))
const getEdgeTypes = computed(() => { const getEdgeTypes = computed(() => {
const edgeTypes: Record<string, any> = { const edgeTypes: Record<string, any> = {
...defaultEdgeTypes, ...defaultEdgeTypes,
@@ -24,6 +28,8 @@ export default (state: State): ComputedGetters => {
}) })
const getNodes = computed<GraphNode[]>(() => { const getNodes = computed<GraphNode[]>(() => {
if (!paneReady.value) return []
const nodes = state.nodes.filter((n) => !n.hidden) const nodes = state.nodes.filter((n) => !n.hidden)
return state.onlyRenderVisibleElements return state.onlyRenderVisibleElements
? nodes && ? nodes &&
@@ -42,6 +48,8 @@ export default (state: State): ComputedGetters => {
}) })
const getEdges = computed<GraphEdge[]>(() => { const getEdges = computed<GraphEdge[]>(() => {
if (!paneReady.value) return []
if (!state.onlyRenderVisibleElements) if (!state.onlyRenderVisibleElements)
return state.edges.filter((e) => !e.hidden && e.targetNode && !e.targetNode.hidden && e.sourceNode && !e.sourceNode.hidden) return state.edges.filter((e) => !e.hidden && e.targetNode && !e.targetNode.hidden && e.sourceNode && !e.sourceNode.hidden)
else else