@@ -15,6 +15,7 @@ import {map} from 'rxjs/operators';
15
15
16
16
/** Flat node with expandable and level information */
17
17
export class DynamicFlatNode {
18
+ isLoading : boolean = false ;
18
19
constructor ( public item : string , public level : number = 1 , public expandable : boolean = false ) { }
19
20
}
20
21
@@ -69,14 +70,14 @@ export class DynamicDataSource {
69
70
private database : DynamicDatabase ) { }
70
71
71
72
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 ||
75
75
( 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 ) ) ;
80
81
}
81
82
82
83
/** Handle expand/collapse behaviors */
@@ -99,16 +100,21 @@ export class DynamicDataSource {
99
100
if ( ! children || index < 0 ) { // If no children, or cannot find the node, no op
100
101
return ;
101
102
}
103
+ node . isLoading = true ;
102
104
103
- if ( expand ) {
104
- const nodes = children . map ( name =>
105
+ setTimeout ( ( ) => {
106
+ if ( expand ) {
107
+ const nodes = children . map ( name =>
105
108
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
+ }
110
113
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 ) ;
113
118
}
119
+
114
120
}
0 commit comments