7
7
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8
8
*/
9
9
10
- import { Component , Input , OnInit , Type } from '@angular/core' ;
10
+ import { Component , model , OnInit , Type } from '@angular/core' ;
11
11
import { merge , Observable , partition , timer } from 'rxjs' ;
12
12
import { debounce , distinctUntilChanged , switchMap , tap } from 'rxjs/operators' ;
13
13
import { SpinnerVisibilityService } from '../services/spinner-visibility.service' ;
@@ -28,18 +28,18 @@ export class NgHttpLoaderComponent implements OnInit {
28
28
isVisible$ ! : Observable < boolean > ;
29
29
visibleUntil = Date . now ( ) ;
30
30
31
- @ Input ( ) backdrop = true ;
32
- @ Input ( ) backgroundColor ! : string ;
33
- @ Input ( ) debounceDelay = 0 ;
34
- @ Input ( ) entryComponent ! : Type < unknown > | null ;
35
- @ Input ( ) extraDuration = 0 ;
36
- @ Input ( ) filteredHeaders : string [ ] = [ ] ;
37
- @ Input ( ) filteredMethods : string [ ] = [ ] ;
38
- @ Input ( ) filteredUrlPatterns : string [ ] = [ ] ;
39
- @ Input ( ) minDuration = 0 ;
40
- @ Input ( ) opacity = '.7' ;
41
- @ Input ( ) backdropBackgroundColor = '#f1f1f1' ;
42
- @ Input ( ) spinner : string | null = Spinkit . skWave ;
31
+ backdrop = model < boolean > ( true ) ;
32
+ backgroundColor = model < string > ( ) ;
33
+ debounceDelay = model < number > ( 0 ) ;
34
+ entryComponent = model < Type < unknown > | null > ( null ) ;
35
+ extraDuration = model < number > ( 0 ) ;
36
+ filteredHeaders = model < string [ ] > ( [ ] ) ;
37
+ filteredMethods = model < string [ ] > ( [ ] ) ;
38
+ filteredUrlPatterns = model < string [ ] > ( [ ] ) ;
39
+ minDuration = model < number > ( 0 ) ;
40
+ opacity = model < string > ( '.7' ) ;
41
+ backdropBackgroundColor = model < string > ( '#f1f1f1' ) ;
42
+ spinner = model < string | null > ( Spinkit . skWave ) ;
43
43
44
44
constructor ( private pendingRequestsInterceptorConfigurer : PendingRequestsInterceptorConfigurer , private spinnerVisibility : SpinnerVisibilityService ) {
45
45
}
@@ -55,7 +55,7 @@ export class NgHttpLoaderComponent implements OnInit {
55
55
56
56
this . isVisible$ = merge (
57
57
this . pendingRequestsInterceptorConfigurer . pendingRequestsStatus$
58
- . pipe ( switchMap ( ( ) => showSpinner$ . pipe ( debounce ( ( ) => timer ( this . debounceDelay ) ) ) ) ) ,
58
+ . pipe ( switchMap ( ( ) => showSpinner$ . pipe ( debounce ( ( ) => timer ( this . debounceDelay ( ) ) ) ) ) ) ,
59
59
showSpinner$
60
60
. pipe ( switchMap ( ( ) => hideSpinner$ . pipe ( debounce ( ( ) => this . getVisibilityTimer$ ( ) ) ) ) ) ,
61
61
this . spinnerVisibility . visibility$
@@ -66,8 +66,8 @@ export class NgHttpLoaderComponent implements OnInit {
66
66
}
67
67
68
68
private nullifySpinnerIfEntryComponentIsDefined ( ) : void {
69
- if ( this . entryComponent ) {
70
- this . spinner = null ;
69
+ if ( this . entryComponent ( ) ) {
70
+ this . spinner . set ( null ) ;
71
71
}
72
72
}
73
73
@@ -78,28 +78,28 @@ export class NgHttpLoaderComponent implements OnInit {
78
78
}
79
79
80
80
private initFilteredUrlPatterns ( ) : void {
81
- if ( ! ! this . filteredUrlPatterns . length ) {
82
- this . filteredUrlPatterns . forEach ( e =>
81
+ if ( ! ! this . filteredUrlPatterns ( ) . length ) {
82
+ this . filteredUrlPatterns ( ) . forEach ( e =>
83
83
this . pendingRequestsInterceptorConfigurer . filteredUrlPatterns . push ( new RegExp ( e ) )
84
84
) ;
85
85
}
86
86
}
87
87
88
88
private initFilteredMethods ( ) : void {
89
- this . pendingRequestsInterceptorConfigurer . filteredMethods = this . filteredMethods ;
89
+ this . pendingRequestsInterceptorConfigurer . filteredMethods = this . filteredMethods ( ) ;
90
90
}
91
91
92
92
private initFilteredHeaders ( ) : void {
93
- this . pendingRequestsInterceptorConfigurer . filteredHeaders = this . filteredHeaders ;
93
+ this . pendingRequestsInterceptorConfigurer . filteredHeaders = this . filteredHeaders ( ) ;
94
94
}
95
95
96
96
private updateExpirationDelay ( showSpinner : boolean ) : void {
97
97
if ( showSpinner ) {
98
- this . visibleUntil = Date . now ( ) + this . minDuration ;
98
+ this . visibleUntil = Date . now ( ) + this . minDuration ( ) ;
99
99
}
100
100
}
101
101
102
102
private getVisibilityTimer$ ( ) : Observable < number > {
103
- return timer ( Math . max ( this . extraDuration , this . visibleUntil - Date . now ( ) ) ) ;
103
+ return timer ( Math . max ( this . extraDuration ( ) , this . visibleUntil - Date . now ( ) ) ) ;
104
104
}
105
105
}
0 commit comments