Skip to content

Commit 7d0a019

Browse files
committed
feat(cdk/tree): flatten data that uses childrenAccessor
1 parent 3e212ea commit 7d0a019

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/cdk/tree/tree.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,17 @@ import {
4343
Subject,
4444
Subscription,
4545
} from 'rxjs';
46-
import {concatMap, map, reduce, startWith, switchMap, take, takeUntil, tap} from 'rxjs/operators';
46+
import {
47+
concatMap,
48+
map,
49+
pairwise,
50+
reduce,
51+
startWith,
52+
switchMap,
53+
take,
54+
takeUntil,
55+
tap,
56+
} from 'rxjs/operators';
4757
import {TreeControl} from './control/tree-control';
4858
import {CdkTreeNodeDef, CdkTreeNodeOutletContext} from './node';
4959
import {CdkTreeNodeOutlet} from './outlet';
@@ -865,6 +875,22 @@ export class CdkTree<T, K = T> implements AfterContentChecked, CollectionViewer,
865875
}
866876
return null;
867877
}
878+
879+
private _flattenChildren(nodes: readonly T[]): Observable<readonly T[]> {
880+
// If we're using TreeControl or levelAccessor, we don't need to manually
881+
// flatten things here.
882+
if (!this.childrenAccessor) {
883+
return observableOf(nodes);
884+
} else {
885+
return observableOf(...nodes).pipe(
886+
concatMap(node => concat(observableOf([node]), this._getAllChildrenRecursively(node))),
887+
reduce((results, nodes) => {
888+
results.push(...nodes);
889+
return results;
890+
}, [] as T[]),
891+
);
892+
}
893+
}
868894
}
869895

870896
/**

0 commit comments

Comments
 (0)