FarmMapsLib/projects/common/src/fm/services/package-preload-strategy.service.ts
Willem Dantuma 964bf925e7
All checks were successful
FarmMaps.Develop/FarmMapsLib/pipeline/head This commit looks good
Fix typo
2020-09-15 15:01:20 +02:00

31 lines
956 B
TypeScript

import { Injectable} from '@angular/core';
import { PreloadingStrategy,Route } from '@angular/router'
import { Observable, EMPTY } from 'rxjs';
import { PackageService} from './package.service';
@Injectable({
providedIn: 'root',
})
export class PackagePreloadStrategy extends PreloadingStrategy {
loading = new Set<Route>();
constructor(private packageService$:PackageService) {
super();
}
preload(route: Route, load: Function): Observable<any> {
if (this.loading.has(route)) {
// Don't preload the same route twice
return EMPTY;
}
if(route.data && route.data.package) {
if(this.packageService$.hasPackage(route.data.package)) {
console.debug(`Load module for package ${route.data.package}`)
this.loading.add(route);
return load()
}
}
return EMPTY;
}
}