From abf00187bb89b1de6ea7a8b45e0920d7766d91a3 Mon Sep 17 00:00:00 2001 From: jasonpul <61257274+jasonpul@users.noreply.github.com> Date: Sun, 11 Oct 2020 17:51:08 -0400 Subject: [PATCH] Update graph.ts added check to verify handle exists in node --- src/utils/graph.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/utils/graph.ts b/src/utils/graph.ts index 700f982b..9c427786 100644 --- a/src/utils/graph.ts +++ b/src/utils/graph.ts @@ -65,10 +65,14 @@ export const addEdge = (edgeParams: Edge | Connection, elements: Elements): Elem throw new Error(`Can't create edge. Node with id=${id} does not exist.`); } }); - // need to check if handles exist - // - // - // + + // make sure that the handles exists in each node + const handleElements = Array.from(document.getElementsByClassName("react-flow__handle")) as HTMLDivElement[] + [[edgeParams.source, edgeParams.sourceHandle], [edgeParams.target, edgeParams.targetHandle]].forEach(([nodeId, handleId]) => { + if (!handleElements.find((he) => he.getAttribute('data-nodeid') === nodeId && he.getAttribute('data-handleid') === handleId)) { + throw new Error(`Can't create edge. Handle with id=${handleId} does not exist within Node with id=${nodeId}.`); + } + }) let edge: Edge if (isEdge(edgeParams)) {