Skip to content

Commit 8464101

Browse files
BobobUnicornandrewseguin
authored andcommitted
feat(cdk/tree): fix comments and improve readability
1 parent 55b3b26 commit 8464101

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

src/cdk/tree/nested-node.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,19 @@ export class CdkNestedTreeNode<T, K = T>
7171
this._dataDiffer = this._differs.find([]).create(this._tree.trackBy);
7272
if (!this._tree.treeControl?.getChildren && (typeof ngDevMode === 'undefined' || ngDevMode)) {
7373
throw getTreeControlFunctionsMissingError();
74-
}
75-
const childrenNodes = this._tree.treeControl!.getChildren(this.data);
76-
if (Array.isArray(childrenNodes)) {
77-
this.updateChildrenNodes(childrenNodes as T[]);
78-
} else if (isObservable(childrenNodes)) {
79-
childrenNodes
74+
} else {
75+
const childrenNodes = this._tree.treeControl!.getChildren(this.data);
76+
if (Array.isArray(childrenNodes)) {
77+
this.updateChildrenNodes(childrenNodes as T[]);
78+
} else if (isObservable(childrenNodes)) {
79+
childrenNodes
80+
.pipe(takeUntil(this._destroyed))
81+
.subscribe(result => this.updateChildrenNodes(result));
82+
}
83+
this.nodeOutlet.changes
8084
.pipe(takeUntil(this._destroyed))
81-
.subscribe(result => this.updateChildrenNodes(result));
85+
.subscribe(() => this.updateChildrenNodes());
8286
}
83-
this.nodeOutlet.changes
84-
.pipe(takeUntil(this._destroyed))
85-
.subscribe(() => this.updateChildrenNodes());
8687
}
8788

8889
// This is a workaround for https://github.com/angular/angular/issues/23091

src/cdk/tree/tree.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ export class CdkTreeNode<T, K = T> implements FocusableOption, OnDestroy, OnInit
479479
protected _data: T;
480480

481481
get level(): number {
482-
// If the treeControl has a getLevel method, use it to get the level. Otherwise read the
482+
// If the tree has a levelAccessor, use it to get the level. Otherwise read the
483483
// aria-level off the parent node and use it as the level for this node (note aria-level is
484484
// 1-indexed, while this property is 0-indexed, so we don't need to increment).
485485
return this._tree._getLevelAccessor()?.(this._data) ?? this._parentNodeAriaLevel;

0 commit comments

Comments
 (0)