rc-js-util
Version:
A collection of TS and C++ utilities to help writing performant and correct applications, achieved through strict typing and (removable) invariant checking.
25 lines • 731 B
JavaScript
/**
* @public
* Iterates over the whole tree, in a depth first fashion.
*
* @param node - The start point.
* @param callback - Called for each node, including the start point.
*
* @remarks
* See {@link treeIterate}.
*/
export function treeIterate(node, callback) {
callback(node, null, 0);
treeRecurseImpl(node, node.getChildren(), 1, callback);
}
function treeRecurseImpl(parent, children, depth, callback) {
if (children == null) {
return;
}
for (let i = 0, iEnd = children.length; i < iEnd; i++) {
const node = children[i];
callback(node, parent, depth);
treeRecurseImpl(node, node.getChildren(), depth + 1, callback);
}
}
//# sourceMappingURL=tree-iterate.js.map