Update graph.ts

added check to verify handle exists in node
This commit is contained in:
jasonpul
2020-10-11 17:51:08 -04:00
committed by GitHub
parent 8742fa5cb8
commit abf00187bb
+8 -4
View File
@@ -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)) {