feat(nodes): add helper functions to iterate over child nodes

This commit is contained in:
Christopher Möller
2021-10-21 11:53:44 +02:00
parent 9350884836
commit 9ad894d2df
7 changed files with 157 additions and 96 deletions
-26
View File
@@ -342,29 +342,3 @@ export function applyNodeChanges(changes: NodeChange[], nodes: Node[]): Node[] {
export function applyEdgeChanges(changes: EdgeChange[], edges: Edge[]): Edge[] {
return applyChanges(changes, edges) as Edge[];
}
function flat(arr: Node[], target: Node[]) {
arr.forEach(function (el) {
if (el.childNodes) {
flat(el.childNodes, target);
} else {
target.push(el);
}
});
}
export function flattenNodes(nodes: Node[]): Node[] {
const flattened: Node[] = [];
flat(nodes, flattened);
return flattened;
// return nodes.reduce<Node[]>((result, node) => {
// result.push(node);
// if (node.childNodes) {
// result.push(...flattenNodes(node.childNodes));
// }
// return result;
// }, []);
}