Skip to content

Commit

Permalink
fix: Return empty arrays if pane isn't ready yet
Browse files Browse the repository at this point in the history
  • Loading branch information
bcakmakoglu committed Apr 9, 2022
1 parent c295a83 commit 6829efc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions package/src/composables/useVueFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export class Storage {
...getters,
...actions,
})

const flow: UseVueFlow = {
...hooksOn,
...getters,
Expand Down
8 changes: 8 additions & 0 deletions package/src/store/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 &&
Expand All @@ -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
Expand Down

0 comments on commit 6829efc

Please sign in to comment.