Compare commits

..

2 Commits

Author SHA1 Message Date
Willem Dantuma
fb8129148d Add to module
All checks were successful
FarmMaps.Develop/FarmMapsLib/pipeline/head This commit looks good
2020-09-15 14:01:24 +02:00
Willem Dantuma
73db03148a First attempt package preload strategy 2020-09-15 14:00:18 +02:00
2 changed files with 34 additions and 1 deletions

View File

@ -30,6 +30,7 @@ import { NgbDateNativeAdapter } from './services/date-adapter.service'
import { AuthConfigFactory } from './shared/authconfigFactory'; import { AuthConfigFactory } from './shared/authconfigFactory';
import { StateSerializerService } from './services/state-serializer.service'; import { StateSerializerService } from './services/state-serializer.service';
import { PackageService } from './services/package.service'; import { PackageService } from './services/package.service';
import { PackagePreloadStartegy } from './services/package-preload-strategy.service';
import { SenmlService } from './services/senml-service'; import { SenmlService } from './services/senml-service';
export { export {
@ -53,7 +54,8 @@ export {
StateSerializerService, StateSerializerService,
SchemaService, SchemaService,
PackageService, PackageService,
SenmlService SenmlService,
PackagePreloadStartegy
}; };
@NgModule({ @NgModule({

View File

@ -0,0 +1,31 @@
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 PackagePreloadStartegy 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;
}
}