@@ -15,6 +15,7 @@ import {map} from 'rxjs/operators';
1515
1616/** Flat node with expandable and level information */
1717export class DynamicFlatNode {
18+ isLoading : boolean = false ;
1819 constructor ( public item : string , public level : number = 1 , public expandable : boolean = false ) { }
1920}
2021
@@ -69,14 +70,14 @@ export class DynamicDataSource {
6970 private database : DynamicDatabase ) { }
7071
7172 connect ( collectionViewer : CollectionViewer ) : Observable < DynamicFlatNode [ ] > {
72- return merge ( collectionViewer . viewChange , this . treeControl . expansionModel . onChange ! )
73- . pipe ( map ( ( change ) => {
74- if ( ( change as SelectionChange < DynamicFlatNode > ) . added ||
73+ this . treeControl . expansionModel . onChange ! . subscribe ( change => {
74+ if ( ( change as SelectionChange < DynamicFlatNode > ) . added ||
7575 ( change as SelectionChange < DynamicFlatNode > ) . removed ) {
76- this . handleTreeControl ( change as SelectionChange < DynamicFlatNode > ) ;
77- }
78- return this . data ;
79- } ) ) ;
76+ this . handleTreeControl ( change as SelectionChange < DynamicFlatNode > ) ;
77+ }
78+ } ) ;
79+
80+ return merge ( collectionViewer . viewChange , this . dataChange ) . pipe ( map ( ( ) => this . data ) ) ;
8081 }
8182
8283 /** Handle expand/collapse behaviors */
@@ -99,16 +100,21 @@ export class DynamicDataSource {
99100 if ( ! children || index < 0 ) { // If no children, or cannot find the node, no op
100101 return ;
101102 }
103+ node . isLoading = true ;
102104
103- if ( expand ) {
104- const nodes = children . map ( name =>
105+ setTimeout ( ( ) => {
106+ if ( expand ) {
107+ const nodes = children . map ( name =>
105108 new DynamicFlatNode ( name , node . level + 1 , this . database . isExpandable ( name ) ) ) ;
106- this . data . splice ( index + 1 , 0 , ...nodes ) ;
107- } else {
108- this . data . splice ( index + 1 , children . length ) ;
109- }
109+ this . data . splice ( index + 1 , 0 , ...nodes ) ;
110+ } else {
111+ this . data . splice ( index + 1 , children . length ) ;
112+ }
110113
111- // notify the change
112- this . dataChange . next ( this . data ) ;
114+ // notify the change
115+ this . dataChange . next ( this . data ) ;
116+ node . isLoading = false ;
117+ } , 1000 ) ;
113118 }
119+
114120}
0 commit comments