From 41743f1ff0d0b45224b74a2ef7b0c75103f37bfa Mon Sep 17 00:00:00 2001 From: victorbrambati Date: Sun, 6 Nov 2022 18:37:40 -0300 Subject: [PATCH] chore: refactor getOutgoers --- src/utils/getOutgoers.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/utils/getOutgoers.ts b/src/utils/getOutgoers.ts index 6d861ea..e1d58d4 100644 --- a/src/utils/getOutgoers.ts +++ b/src/utils/getOutgoers.ts @@ -6,20 +6,20 @@ export const getOutgoers = ( ): [NodeData[], string[]] => { const outgoerNodes: NodeData[] = []; const matchingNodes: string[] = []; + + if (parent.includes(nodeId)) { + const initialParentNode = nodes.find(n => n.id === nodeId); + if (initialParentNode) outgoerNodes.push(initialParentNode); + } + const runner = (nodeId: string) => { const outgoerIds = edges.filter(e => e.from === nodeId).map(e => e.to); - - if (parent.includes(nodeId)) { - const initialParentNode = nodes.find(n => n.id === nodeId); - if (initialParentNode) outgoerNodes.push(initialParentNode); - } - const nodeList = nodes.filter(n => { if (parent.includes(n.id) && !matchingNodes.includes(n.id)) matchingNodes.push(n.id); return outgoerIds.includes(n.id) && !parent.includes(n.id); }); - + outgoerNodes.push(...nodeList); nodeList.forEach(node => runner(node.id)); };