-
Notifications
You must be signed in to change notification settings - Fork 6.8k
feat(tree): support array of data as children in nested tree #10886
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(tree): support array of data as children in nested tree #10886
Conversation
a7b0c2d
to
f1b20ac
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Are there any examples that could be simplified with this?
- Should the docs be updated anywhere based on this?
src/cdk/tree/tree.ts
Outdated
if (Array.isArray(childrenNodes)) { | ||
this._setRoleFromChildren(childrenNodes as T[]); | ||
} else if (childrenNodes instanceof Observable) { | ||
childrenNodes.pipe(takeUntil(this._destroyed)).subscribe(this._setRoleFromChildren); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might be getting an incorrect this
inside _setRoleFromChildren
by passing in the function like this.
if (Array.isArray(childrenNodes)) { | ||
childrenNodes.forEach((child: T) => this._getDescendants(descendants, child)); | ||
} else if (childrenNodes instanceof Observable) { | ||
childrenNodes.pipe(take(1)).subscribe(children => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is being done recursively and childrenNodes
can be async, couldn't this potentially lead to some race conditions?
childrenNodes.forEach((child: T) => this._getDescendants(descendants, child)); | ||
} else if (childrenNodes instanceof Observable) { | ||
childrenNodes.pipe(take(1)).subscribe(children => { | ||
if (children && children.length > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK forEach
will handle the case where children.length === 0
for you.
|
||
treeControl.expandAll(); | ||
|
||
const totalNumber = numNodes + numNodes * numChildren |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding parentheses around some of these to make it easier to follow.
f1b20ac
to
5e231f0
Compare
Hi @tinayuangao! This PR has merge conflicts due to recent upstream merges. |
1 similar comment
Hi @tinayuangao! This PR has merge conflicts due to recent upstream merges. |
0630fe6
to
27a2b5a
Compare
27a2b5a
to
1b14996
Compare
@jelbourn Updated example and docs. Please take a look. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Gracefully handles nodes whose children are set to null. This seems to be something that we used to handle until a regression from angular#10886. Fixes angular#14545.
Gracefully handles nodes whose children are set to null. This seems to be something that we used to handle until a regression from angular#10886. Fixes angular#14545.
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
No description provided.