瀏覽代碼

chore: refactor getOutgoers

victorbrambati 2 年之前
父節點
當前提交
41743f1ff0
共有 1 個文件被更改,包括 7 次插入7 次删除
  1. 7 7
      src/utils/getOutgoers.ts

+ 7 - 7
src/utils/getOutgoers.ts

@@ -6,20 +6,20 @@ export const getOutgoers = (
 ): [NodeData[], string[]] => {
   const outgoerNodes: NodeData[] = [];
   const matchingNodes: string[] = [];
-  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);
-    }
+  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);
     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));
   };