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,
...actions,
})
const flow: UseVueFlow = {
...hooksOn,
...getters,
+8
View File
@@ -3,6 +3,10 @@ import { State, GraphEdge, GraphNode, ComputedGetters } from '~/types'
import { getNodesInside, isEdgeVisible } from '~/utils'
export default (state: State): ComputedGetters => {
const paneReady = ref(false)
state.hooks.paneReady.on(() => (paneReady.value = true))
const getEdgeTypes = computed(() => {
const edgeTypes: Record<string, any> = {
...defaultEdgeTypes,
@@ -24,6 +28,8 @@ export default (state: State): ComputedGetters => {
})
const getNodes = computed<GraphNode[]>(() => {
if (!paneReady.value) return []
const nodes = state.nodes.filter((n) => !n.hidden)
return state.onlyRenderVisibleElements
? nodes &&
@@ -42,6 +48,8 @@ export default (state: State): ComputedGetters => {
})
const getEdges = computed<GraphEdge[]>(() => {
if (!paneReady.value) return []
if (!state.onlyRenderVisibleElements)
return state.edges.filter((e) => !e.hidden && e.targetNode && !e.targetNode.hidden && e.sourceNode && !e.sourceNode.hidden)
else