Skip to content

Commit 478871c

Browse files
committed
Add 'debounceDelay' option to not show the spinner immediately when needed
1 parent bd7a229 commit 478871c

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/components/spinner/spinner.component.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import { Component, Input, OnDestroy, OnInit } from '@angular/core';
1111
import { Subscription } from 'rxjs/Subscription';
1212
import { Spinkit } from '../../spinkits';
1313
import { PendingInterceptorService } from '../../services/pending-interceptor.service';
14+
import { timer } from 'rxjs/observable/timer';
15+
import { Observable } from 'rxjs/Observable';
16+
import 'rxjs/add/operator/debounce';
1417

1518
@Component({
1619
selector: 'spinner',
@@ -28,10 +31,13 @@ export class SpinnerComponent implements OnDestroy, OnInit {
2831
public spinner = Spinkit.skCubeGrid;
2932
@Input()
3033
public filteredUrlPatterns: string[] = [];
34+
@Input()
35+
public debounceDelay = 0;
3136

3237
constructor(private pendingRequestInterceptorService: PendingInterceptorService) {
3338
this.subscription = this.pendingRequestInterceptorService
3439
.pendingRequestsStatus
40+
.debounce(this.handleDebounce.bind(this))
3541
.subscribe(hasPendingRequests => {
3642
this.isSpinnerVisible = hasPendingRequests;
3743
});
@@ -52,4 +58,12 @@ export class SpinnerComponent implements OnDestroy, OnInit {
5258
ngOnDestroy(): void {
5359
this.subscription.unsubscribe();
5460
}
61+
62+
private handleDebounce(hasPendingRequests: boolean): Observable<number> {
63+
if (hasPendingRequests) {
64+
return timer(this.debounceDelay);
65+
}
66+
67+
return timer(0);
68+
}
5569
}

0 commit comments

Comments
 (0)