fix(nodes): performance issue with getNode

This commit is contained in:
bcakmakoglu
2022-06-03 22:48:54 +02:00
committed by Braks
parent f272bd60d7
commit 0102ebcd33
2 changed files with 12 additions and 4 deletions

View File

@@ -3,8 +3,16 @@ import type { ComputedGetters, GraphEdge, GraphNode, State } from '~/types'
import { getNodesInside, isEdgeVisible } from '~/utils'
export default (state: State): ComputedGetters => {
const getNode: ComputedGetters['getNode'] = computed(() => (id: string) => state.nodes.find((node) => node.id === id))
const getEdge: ComputedGetters['getEdge'] = computed(() => (id: string) => state.edges.find((edge) => edge.id === id))
const nodeIds = computed(() => state.nodes.map((n) => n.id))
const edgeIds = computed(() => state.edges.map((e) => e.id))
const getNode: ComputedGetters['getNode'] = computed(() => (id: string) => {
if (state.nodes && !nodeIds.value.length) return state.nodes.find((node) => node.id === id)
return state.nodes[nodeIds.value.indexOf(id)]
})
const getEdge: ComputedGetters['getEdge'] = computed(() => (id: string) => {
if (state.edges && !edgeIds.value.length) return state.edges.find((edge) => edge.id === id)
return state.edges[edgeIds.value.indexOf(id)]
})
const getEdgeTypes = computed(() => {
const edgeTypes: Record<string, any> = {

View File

@@ -103,7 +103,7 @@ export const applyChanges = <
}
if (el.expandParent && el.parentNode) {
const parent = elements.find((parent) => parent.id === el.parentNode)
const parent = elements[elementIds.indexOf(el.parentNode)]
if (parent && isGraphNode(parent)) {
handleParentExpand(el, parent)
@@ -115,7 +115,7 @@ export const applyChanges = <
if (isGraphNode(el)) {
if (typeof change.dimensions !== 'undefined') el.dimensions = change.dimensions
if (el.expandParent && el.parentNode) {
const parent = elements.find((parent) => parent.id === el.parentNode)
const parent = elements[elementIds.indexOf(el.parentNode)]
if (parent && isGraphNode(parent)) {
handleParentExpand(el, parent)