fix: Return empty arrays if pane isn't ready yet
This commit is contained in:
@@ -53,6 +53,7 @@ export class Storage {
|
|||||||
...getters,
|
...getters,
|
||||||
...actions,
|
...actions,
|
||||||
})
|
})
|
||||||
|
|
||||||
const flow: UseVueFlow = {
|
const flow: UseVueFlow = {
|
||||||
...hooksOn,
|
...hooksOn,
|
||||||
...getters,
|
...getters,
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user