Skip to content

Commit

Permalink
fix(cdk/tree): formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
BobobUnicorn committed Sep 17, 2024
1 parent 8c0222a commit b6b1ea2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/cdk/tree/tree.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2183,6 +2183,6 @@ class NestedChildrenExpansionTest {
data[0].children = children;

this.dataSource = data;
this.allNodes = [...data, ...children, ... nestedChildren];
this.allNodes = [...data, ...children, ...nestedChildren];
}
}
35 changes: 21 additions & 14 deletions src/cdk/tree/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,18 +273,21 @@ export class CdkTree<T, K = T>

constructor(...args: unknown[]);
constructor() {
effect(onCleanup => {
const data = this._data();
const nodeType = this._nodeType();
const expandedKeys = this._selection();

const sub = this._getRenderData(data, nodeType, expandedKeys).subscribe(renderData => {
this._renderDataChanges(renderData);
});
onCleanup(() => {
sub.unsubscribe();
});
}, {allowSignalWrites: true});
effect(
onCleanup => {
const data = this._data();
const nodeType = this._nodeType();
const expandedKeys = this._selection();

const sub = this._getRenderData(data, nodeType, expandedKeys).subscribe(renderData => {
this._renderDataChanges(renderData);
});
onCleanup(() => {
sub.unsubscribe();
});
},
{allowSignalWrites: true},
);
}

ngAfterContentInit() {
Expand Down Expand Up @@ -1004,7 +1007,11 @@ export class CdkTree<T, K = T>
* This will still traverse all nested children in order to build up our internal data
* models, but will not include them in the returned array.
*/
private _flattenNestedNodesWithExpansion(nodes: readonly T[], selection: readonly K[], level = 0): Observable<T[]> {
private _flattenNestedNodesWithExpansion(
nodes: readonly T[],
selection: readonly K[],
level = 0,
): Observable<T[]> {
const childrenAccessor = this._getChildrenAccessor();
// If we're using a level accessor, we don't need to flatten anything.
if (!childrenAccessor) {
Expand Down Expand Up @@ -1037,7 +1044,7 @@ export class CdkTree<T, K = T>
return observableOf([]);
}
return this._flattenNestedNodesWithExpansion(childNodes, selection, level + 1).pipe(
map(nestedNodes => selection.includes(parentKey) ? nestedNodes : []),
map(nestedNodes => (selection.includes(parentKey) ? nestedNodes : [])),
);
}),
),
Expand Down

0 comments on commit b6b1ea2

Please sign in to comment.