initial release
This commit is contained in:
28
bizmatch/src/app/services/loading.service.ts
Normal file
28
bizmatch/src/app/services/loading.service.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { BehaviorSubject, debounceTime, distinctUntilChanged, map, shareReplay } from 'rxjs';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class LoadingService {
|
||||
public loading$ = new BehaviorSubject<string[]>([]);
|
||||
|
||||
public isLoading$ = this.loading$.asObservable().pipe(
|
||||
map((loading) => loading.length > 0),
|
||||
debounceTime(200),
|
||||
distinctUntilChanged(),
|
||||
shareReplay(1)
|
||||
);
|
||||
|
||||
public startLoading(type: string): void {
|
||||
if (!this.loading$.value.includes(type)) {
|
||||
this.loading$.next(this.loading$.value.concat(type));
|
||||
}
|
||||
}
|
||||
|
||||
public stopLoading(type: string): void {
|
||||
if (this.loading$.value.includes(type)) {
|
||||
this.loading$.next(this.loading$.value.filter((t) => t !== type));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user