|
|
|
@ -1,9 +1,10 @@ |
|
|
|
import { Injectable, Injector } from '@angular/core'; |
|
|
|
import { NavigationCancel, NavigationEnd, NavigationError, NavigationStart, Router } from '@angular/router'; |
|
|
|
import { filter, map, mapTo, switchMap, takeUntil, tap } from 'rxjs/operators'; |
|
|
|
import { InternalStore } from '../utils/internal-store-utils'; |
|
|
|
import { NavigationStart } from '@angular/router'; |
|
|
|
import { of, Subject, timer } from 'rxjs'; |
|
|
|
import { map, mapTo, switchMap, takeUntil, tap } from 'rxjs/operators'; |
|
|
|
import { LOADER_DELAY } from '../tokens/lodaer-delay.token'; |
|
|
|
import { InternalStore } from '../utils/internal-store-utils'; |
|
|
|
import { NavigationEvents } from './navigation-events.service'; |
|
|
|
|
|
|
|
export interface RouterWaitState { |
|
|
|
loading: boolean; |
|
|
|
@ -16,17 +17,15 @@ export class RouterWaitService { |
|
|
|
private store = new InternalStore<RouterWaitState>({ loading: false }); |
|
|
|
private destroy$ = new Subject(); |
|
|
|
private delay: number; |
|
|
|
constructor(private router: Router, injector: Injector) { |
|
|
|
constructor(private navigationEvents: NavigationEvents, injector: Injector) { |
|
|
|
this.delay = injector.get(LOADER_DELAY, 500); |
|
|
|
this.router.events |
|
|
|
this.updateLoadingStatusOnNavigationEvents(); |
|
|
|
} |
|
|
|
|
|
|
|
private updateLoadingStatusOnNavigationEvents() { |
|
|
|
this.navigationEvents |
|
|
|
.getAny() |
|
|
|
.pipe( |
|
|
|
filter( |
|
|
|
event => |
|
|
|
event instanceof NavigationStart || |
|
|
|
event instanceof NavigationEnd || |
|
|
|
event instanceof NavigationError || |
|
|
|
event instanceof NavigationCancel, |
|
|
|
), |
|
|
|
map(event => event instanceof NavigationStart), |
|
|
|
switchMap(condition => |
|
|
|
condition |
|
|
|
|