Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export class TreeChecklistExample {
: new TodoItemFlatNode();
flatNode.item = node.item;
flatNode.level = level;
flatNode.expandable = !!node.children;
flatNode.expandable = !!node.children?.length;
this.flatNodeMap.set(flatNode, node);
this.nestedNodeMap.set(node, flatNode);
return flatNode;
Expand All @@ -171,9 +171,9 @@ export class TreeChecklistExample {
/** Whether all the descendants of the node are selected. */
descendantsAllSelected(node: TodoItemFlatNode): boolean {
const descendants = this.treeControl.getDescendants(node);
const descAllSelected = descendants.every(child =>
this.checklistSelection.isSelected(child)
);
const descAllSelected = descendants.length > 0 && descendants.every(child => {
return this.checklistSelection.isSelected(child);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: why add the {} and return?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just find it more readable compared to the multi-line arrow function with an implicit return.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer the implicit return, but I don't think we have an official style on way or the other

});
return descAllSelected;
}

Expand All @@ -193,9 +193,7 @@ export class TreeChecklistExample {
: this.checklistSelection.deselect(...descendants);

// Force update for the parent
descendants.every(child =>
this.checklistSelection.isSelected(child)
);
descendants.forEach(child => this.checklistSelection.isSelected(child));
this.checkAllParentsSelection(node);
}

Expand All @@ -218,9 +216,9 @@ export class TreeChecklistExample {
checkRootNodeSelection(node: TodoItemFlatNode): void {
const nodeSelected = this.checklistSelection.isSelected(node);
const descendants = this.treeControl.getDescendants(node);
const descAllSelected = descendants.every(child =>
this.checklistSelection.isSelected(child)
);
const descAllSelected = descendants.length > 0 && descendants.every(child => {
return this.checklistSelection.isSelected(child);
});
if (nodeSelected && !descAllSelected) {
this.checklistSelection.deselect(node);
} else if (!nodeSelected && descAllSelected) {
Expand Down