aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/core/routing/preload-selected-modules-list.ts
blob: 64af68225d20763a9a242a6afccfdce7b73f49aa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import { Observable, of as ofObservable, timer as observableTimer } from 'rxjs'
import { switchMap } from 'rxjs/operators'
import { PreloadingStrategy, Route } from '@angular/router'
import { Injectable } from '@angular/core'

@Injectable()
export class PreloadSelectedModulesList implements PreloadingStrategy {
  preload (route: Route, load: Function): Observable<any> {
    if (!route.data || !route.data.preload) return ofObservable(null)

    if (typeof route.data.preload === 'number') {
      return observableTimer(route.data.preload).pipe(switchMap(() => load()))
    }

    return load()
  }
}