From 1171e01c9c9d63a0b375a5ce7b2f7ffd535e088d Mon Sep 17 00:00:00 2001 From: braks <78412429+bcakmakoglu@users.noreply.github.com> Date: Fri, 7 Apr 2023 22:00:50 +0200 Subject: [PATCH] refactor(core): allow passing undefined as arg to `findNode` & `findEdge` Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com> --- packages/core/src/store/actions.ts | 8 ++++++++ packages/core/src/types/store.ts | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/core/src/store/actions.ts b/packages/core/src/store/actions.ts index 95529da3..0d0b4fa8 100644 --- a/packages/core/src/store/actions.ts +++ b/packages/core/src/store/actions.ts @@ -38,6 +38,10 @@ export function useActions( } const findNode: Actions['findNode'] = (id) => { + if (!id) { + return + } + if (state.nodes && !nodeIds.value.length) { return state.nodes.find((node) => node.id === id) } @@ -46,6 +50,10 @@ export function useActions( } const findEdge: Actions['findEdge'] = (id) => { + if (!id) { + return + } + if (state.edges && !edgeIds.value.length) { return state.edges.find((edge) => edge.id === id) } diff --git a/packages/core/src/types/store.ts b/packages/core/src/types/store.ts index 6523317a..2a363f73 100644 --- a/packages/core/src/types/store.ts +++ b/packages/core/src/types/store.ts @@ -179,11 +179,11 @@ export type UpdateNodeDimensions = (updates: UpdateNodeDimensionsParams[]) => vo export type UpdateNodeInternals = (nodeIds?: string[]) => void export type FindNode = = any>( - id: string, + id: string | undefined, ) => GraphNode | undefined export type FindEdge = = any>( - id: string, + id: string | undefined, ) => GraphEdge | undefined export type GetIntersectingNodes = (