Fix branchedResetPropagation #57
1 changed files with 15 additions and 28 deletions
|
@ -338,34 +338,21 @@ export const branchedResetPropagation = function (
|
||||||
tree: GenericTree,
|
tree: GenericTree,
|
||||||
resettingNode: GenericTreeNode
|
resettingNode: GenericTreeNode
|
||||||
): void {
|
): void {
|
||||||
const visitedNodes = [resettingNode];
|
const links = unref(tree.branches);
|
||||||
let currentNodes = [resettingNode];
|
if (links == null) return;
|
||||||
|
|||||||
if (tree.branches != null) {
|
const reset: GenericTreeNode[] = [];
|
||||||
const branches = unref(tree.branches);
|
let current = [resettingNode];
|
||||||
while (currentNodes.length > 0) {
|
while (current.length != 0) {
|
||||||
const nextNodes: GenericTreeNode[] = [];
|
const next: GenericTreeNode[] = [];
|
||||||
thepaperpilot
commented
The linter says next, node, and link should all be The linter says next, node, and link should all be `const`
nif
commented
that's probably because i use that's probably because i use `Array.prototype.concat` and `Array.prototype.push` instead of reassigning them
|
|||||||
currentNodes.forEach(node => {
|
for (const node of current) {
|
||||||
branches
|
for (const link of links.filter(link => link.startNode === node)) {
|
||||||
.filter(branch => branch.startNode === node || branch.endNode === node)
|
if ([...reset, ...current].includes(link.endNode)) continue
|
||||||
.map(branch => {
|
next.push(link.endNode);
|
||||||
if (branch.startNode === node) {
|
link.endNode.reset?.reset();
|
||||||
return branch.endNode;
|
}
|
||||||
}
|
};
|
||||||
return branch.startNode;
|
reset.push(...current);
|
||||||
thepaperpilot
commented
This line is fine, but I wonder why you don't just This line is fine, but I wonder why you don't just `push` like you do the `next` array.
nif
commented
because then that gives a shaped array that can't be iterated over as well because then that gives a shaped array that can't be iterated over as well
nif
commented
wait no i could have wait no i could have `.push(...`'ed
|
|||||||
})
|
current = next;
|
||||||
.filter(node => !visitedNodes.includes(node))
|
|
||||||
.forEach(node => {
|
|
||||||
// Check here instead of in the filter because this check's results may
|
|
||||||
// change as we go through each node
|
|
||||||
if (!nextNodes.includes(node)) {
|
|
||||||
nextNodes.push(node);
|
|
||||||
node.reset?.reset();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
currentNodes = nextNodes;
|
|
||||||
visitedNodes.push(...currentNodes);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue
instead of
=== undefined
, can you use== null
? That matches the rest of the codebase and has subtly different behavior.You very well could, I didn't realise that
== null
tested forundefined