MCPcopy Index your code
hub / github.com/angular/components / _findChildrenByLevel

Method _findChildrenByLevel

src/cdk/tree/tree.ts:789–816  ·  view source on GitHub ↗

* Given the list of flattened nodes, the level accessor, and the level range within * which to consider children, finds the children for a given node. * * For example, for direct children, `levelDelta` would be 1. For all descendants, * `levelDelta` would be Infinity.

(
    levelAccessor: (node: T) => number,
    flattenedNodes: readonly T[],
    dataNode: T,
    levelDelta: number,
  )

Source from the content-addressed store, hash-verified

787 * `levelDelta` would be Infinity.
788 */
789 private _findChildrenByLevel(
790 levelAccessor: (node: T) => number,
791 flattenedNodes: readonly T[],
792 dataNode: T,
793 levelDelta: number,
794 ): T[] {
795 const key = this._getExpansionKey(dataNode);
796 const startIndex = flattenedNodes.findIndex(node => this._getExpansionKey(node) === key);
797 const dataNodeLevel = levelAccessor(dataNode);
798 const expectedLevel = dataNodeLevel + levelDelta;
799 const results: T[] = [];
800
801 // Goes through flattened tree nodes in the `flattenedNodes` array, and get all
802 // descendants within a certain level range.
803 //
804 // If we reach a node whose level is equal to or less than the level of the tree node,
805 // we hit a sibling or parent's sibling, and should stop.
806 for (let i = startIndex + 1; i < flattenedNodes.length; i++) {
807 const currentLevel = levelAccessor(flattenedNodes[i]);
808 if (currentLevel <= dataNodeLevel) {
809 break;
810 }
811 if (currentLevel <= expectedLevel) {
812 results.push(flattenedNodes[i]);
813 }
814 }
815 return results;
816 }
817
818 /**
819 * Adds the specified node component to the tree's internal registry.

Callers 2

_getDirectChildrenMethod · 0.95
_getDescendantsMethod · 0.95

Calls 2

_getExpansionKeyMethod · 0.95
pushMethod · 0.65

Tested by

no test coverage detected