Skip to content

Commit cf762dc

Browse files
committed
feat(cdk/tree): add cache of nodes to the tree
1 parent deb1f37 commit cf762dc

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/cdk/tree/tree.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ function coerceObservable<T>(data: T | Observable<T>): Observable<T> {
6060
return data;
6161
}
6262

63+
function isNotNullish<T>(val: T | null | undefined): val is T {
64+
return val != null;
65+
}
66+
6367
/**
6468
* CDK tree component that connects with a data source to retrieve data of type `T` and renders
6569
* dataNodes with hierarchy. Updates the dataNodes when new data is provided by the data source.
@@ -656,6 +660,22 @@ export class CdkTree<T, K = T> implements AfterContentChecked, CollectionViewer,
656660
return group.indexOf(dataNode) + 1;
657661
}
658662

663+
/**
664+
* Adds the specified node component to the tree's internal registry.
665+
*
666+
* This primarily facilitates keyboard navigation.
667+
*/
668+
_registerNode(node: CdkTreeNode<T, K>) {
669+
this._nodes.value.set(this._trackExpansionKey(node.data), node);
670+
this._nodes.next(this._nodes.value);
671+
}
672+
673+
/** Removes the specified node component from the tree's internal registry. */
674+
_unregisterNode(node: CdkTreeNode<T, K>) {
675+
this._nodes.value.delete(this._trackExpansionKey(node.data));
676+
this._nodes.next(this._nodes.value);
677+
}
678+
659679
private _getAllDescendants(): Observable<T[]> {
660680
return merge(...this._dataNodes.value.map(dataNode => this._getDescendants(dataNode)));
661681
}

0 commit comments

Comments
 (0)