INNER CODE UNIT · JavaScript
sortedNodes
AscensionGameDev/Intersect-Engine · Intersect.Server/wwwroot/js/assets.js:967
const sortedNodes = addNodes.toSorted((a, b) => a?.id?.localeCompare(b?.id) ?? 1);
for (const node of sortedNodes) {
const parent = this.#navigateToParent(this.#tree, node.Path, true);
if (parent === null) {
console.warn('Parent was null?')
continue;
}
const indexInParent = parent.children.findIndex(c => c.id === node.id);
if (indexInParent < 0) {
console.debug(`Adding node '${node.Path}' (did not find ${node.id} in ${parent.id}'s children)`);
parent.children.push(node);
continue;
}
const existingNode = parent.children[indexInParent] ?? node;
console.debug(`Updating node '${node.Path}' (${existingNode.children?.length})`);
parent.children[indexInParent] = Object.assign(existingNode, node, { children: existingNode.children ?? node.children });