feat(nodes): add helper functions to iterate over child nodes
This commit is contained in:
@@ -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;
|
||||
// }, []);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user