@@ -11,10 +11,11 @@ import { Component, Input, OnDestroy, OnInit } from '@angular/core';
1111import { Subscription } from 'rxjs/Subscription' ;
1212import { Spinkit } from '../../spinkits' ;
1313import { PendingInterceptorService } from '../../services/pending-interceptor.service' ;
14+ import { SpinnerVisibilityService } from '../../services/spinner-visibility.service' ;
1415import { timer } from 'rxjs/observable/timer' ;
1516import { Observable } from 'rxjs/Observable' ;
17+ import { merge } from 'rxjs/observable/merge' ;
1618import { debounce } from 'rxjs/operators' ;
17- import { SpinnerVisibilityService } from '../../services/spinner-visibility.service' ;
1819
1920@Component ( {
2021 selector : 'spinner' ,
@@ -23,8 +24,7 @@ import { SpinnerVisibilityService } from '../../services/spinner-visibility.serv
2324} )
2425export class SpinnerComponent implements OnDestroy , OnInit {
2526 public isSpinnerVisible : boolean ;
26- private pendingSubscription : Subscription ;
27- private visibilitySubscription : Subscription ;
27+ private subscriptions : Subscription ;
2828
2929 public Spinkit = Spinkit ;
3030 @Input ( )
@@ -39,13 +39,10 @@ export class SpinnerComponent implements OnDestroy, OnInit {
3939 public entryComponent : any = null ;
4040
4141 constructor ( private pendingInterceptorService : PendingInterceptorService , private spinnerVisibilityService : SpinnerVisibilityService ) {
42- this . pendingSubscription = this . pendingInterceptorService
43- . pendingRequestsStatus
44- . pipe ( debounce ( this . handleDebounce . bind ( this ) ) )
45- . subscribe ( this . handleSpinnerVisibility ( ) . bind ( this ) ) ;
46-
47- this . visibilitySubscription = this . spinnerVisibilityService
48- . visibilityObservable
42+ this . subscriptions = merge (
43+ this . pendingInterceptorService . pendingRequestsStatus . pipe ( debounce ( this . handleDebounce . bind ( this ) ) ) ,
44+ this . spinnerVisibilityService . visibilityObservable ,
45+ )
4946 . subscribe ( this . handleSpinnerVisibility ( ) . bind ( this ) ) ;
5047 }
5148
@@ -64,8 +61,7 @@ export class SpinnerComponent implements OnDestroy, OnInit {
6461 }
6562
6663 ngOnDestroy ( ) : void {
67- this . pendingSubscription . unsubscribe ( ) ;
68- this . visibilitySubscription . unsubscribe ( ) ;
64+ this . subscriptions . unsubscribe ( ) ;
6965 }
7066
7167 private nullifySpinnerIfComponentOutletIsDefined ( ) : void {
0 commit comments