fix(nodes): performance issue with getNode
This commit is contained in:
@@ -3,8 +3,16 @@ import type { ComputedGetters, GraphEdge, GraphNode, State } from '~/types'
|
|||||||
import { getNodesInside, isEdgeVisible } from '~/utils'
|
import { getNodesInside, isEdgeVisible } from '~/utils'
|
||||||
|
|
||||||
export default (state: State): ComputedGetters => {
|
export default (state: State): ComputedGetters => {
|
||||||
const getNode: ComputedGetters['getNode'] = computed(() => (id: string) => state.nodes.find((node) => node.id === id))
|
const nodeIds = computed(() => state.nodes.map((n) => n.id))
|
||||||
const getEdge: ComputedGetters['getEdge'] = computed(() => (id: string) => state.edges.find((edge) => edge.id === 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 getEdgeTypes = computed(() => {
|
||||||
const edgeTypes: Record<string, any> = {
|
const edgeTypes: Record<string, any> = {
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ export const applyChanges = <
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (el.expandParent && el.parentNode) {
|
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)) {
|
if (parent && isGraphNode(parent)) {
|
||||||
handleParentExpand(el, parent)
|
handleParentExpand(el, parent)
|
||||||
@@ -115,7 +115,7 @@ export const applyChanges = <
|
|||||||
if (isGraphNode(el)) {
|
if (isGraphNode(el)) {
|
||||||
if (typeof change.dimensions !== 'undefined') el.dimensions = change.dimensions
|
if (typeof change.dimensions !== 'undefined') el.dimensions = change.dimensions
|
||||||
if (el.expandParent && el.parentNode) {
|
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)) {
|
if (parent && isGraphNode(parent)) {
|
||||||
handleParentExpand(el, parent)
|
handleParentExpand(el, parent)
|
||||||
|
|||||||
Reference in New Issue
Block a user