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

Method _findParentForNode

src/cdk/tree/tree.ts:977–994  ·  view source on GitHub ↗

* Finds the parent for the given node. If this is a root node, this * returns null. If we're unable to determine the parent, for example, * if we don't have cached node data, this returns undefined.

(node: T, index: number, cachedNodes: readonly T[])

Source from the content-addressed store, hash-verified

975 * if we don't have cached node data, this returns undefined.
976 */
977 private _findParentForNode(node: T, index: number, cachedNodes: readonly T[]): T | null {
978 // In all cases, we have a mapping from node to level; all we need to do here is backtrack in
979 // our flattened list of nodes to determine the first node that's of a level lower than the
980 // provided node.
981 if (!cachedNodes.length) {
982 return null;
983 }
984 const currentLevel = this._levels.get(this._getExpansionKey(node)) ?? 0;
985 for (let parentIndex = index - 1; parentIndex >= 0; parentIndex--) {
986 const parentNode = cachedNodes[parentIndex];
987 const parentLevel = this._levels.get(this._getExpansionKey(parentNode)) ?? 0;
988
989 if (parentLevel < currentLevel) {
990 return parentNode;
991 }
992 }
993 return null;
994 }
995
996 /**
997 * Given a set of root nodes and the current node level, flattens any nested

Callers 1

_calculateParentsMethod · 0.95

Calls 2

_getExpansionKeyMethod · 0.95
getMethod · 0.65

Tested by

no test coverage detected