Skip to content

Commit

Permalink
fix: modified linkedlist maintenance func
Browse files Browse the repository at this point in the history
  • Loading branch information
seankwarren committed Jun 6, 2023
1 parent 0f25c34 commit ca6b860
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,12 @@ export function setUnitsHead(units) {
* @returns units {Unit[]}
*/
export function setNextLinks(units) {
const flowchartIds = units.map((u) => u.flowchartId);
console.log("fixing next fields");
for (let i = 0; i < units.length - 1; i++) {
if (!units[i].next) {
// newly added units don't have next set yet => set it
units[i].next = units[i + 1].flowchartId;
if (i > 0) units[i - 1].next = units[i].flowchartId;
} else if (!flowchartIds.includes(units[i].next)) {
// newly removed units may create broken next links => fix it
units[i].next = units[i + 1].flowchartId;
}
units[i].next = units[i + 1].flowchartId;
}
// for the last unit in the list, set next to null or undefined
units[units.length - 1].next = null;
return units;
}

Expand Down

0 comments on commit ca6b860

Please sign in to comment.