add min loading time to loading service
This commit is contained in:
parent
e3f5beb509
commit
8e995e2afe
@ -1,11 +1,14 @@
|
||||
import { EventEmitter, Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
const MIN_LOADING_TIME = 300;
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class LoadingService {
|
||||
private readonly _loadingEvent = new EventEmitter();
|
||||
private _loadingStarted: number;
|
||||
|
||||
get isLoading(): Observable<boolean> {
|
||||
return this._loadingEvent;
|
||||
@ -13,9 +16,18 @@ export class LoadingService {
|
||||
|
||||
start(): void {
|
||||
this._loadingEvent.next(true);
|
||||
this._loadingStarted = new Date().getTime();
|
||||
}
|
||||
|
||||
stop(): void {
|
||||
const timeDelta = new Date().getTime() - this._loadingStarted;
|
||||
if (timeDelta < MIN_LOADING_TIME) {
|
||||
setTimeout(() => {
|
||||
this._loadingEvent.next(false);
|
||||
}, MIN_LOADING_TIME - timeDelta);
|
||||
return;
|
||||
}
|
||||
|
||||
this._loadingEvent.next(false);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user