Skip to content

Commit

Permalink
reduce nesting
Browse files Browse the repository at this point in the history
  • Loading branch information
despairblue committed Oct 18, 2024
1 parent 832e8a1 commit 824db4e
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions packages/core/src/PartialExecutionUtils/handleCycles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,26 @@ export function handleCycles(

// For each start node, check if the node is part of a cycle and if it is
// replace the start node with the start of the cycle.
if (cycles.length) {
for (const startNode of startNodes) {
for (const cycle of cycles) {
const isPartOfCycle = cycle.has(startNode);
if (isPartOfCycle) {
const firstNode = graph.depthFirstSearch({
from: trigger,
fn: (node) => cycle.has(node),
});
if (cycles.length === 0) {
return newStartNodes;
}

for (const startNode of startNodes) {
for (const cycle of cycles) {
const isPartOfCycle = cycle.has(startNode);
if (isPartOfCycle) {
const firstNode = graph.depthFirstSearch({
from: trigger,
fn: (node) => cycle.has(node),
});

a.ok(
firstNode,
"the trigger must be connected to the cycle, otherwise the cycle wouldn't be part of the subgraph",
);
a.ok(
firstNode,
"the trigger must be connected to the cycle, otherwise the cycle wouldn't be part of the subgraph",
);

newStartNodes.delete(startNode);
newStartNodes.add(firstNode);
}
newStartNodes.delete(startNode);
newStartNodes.add(firstNode);
}
}
}
Expand Down

0 comments on commit 824db4e

Please sign in to comment.