Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,31 @@ export class IdlePreload /*implements PreloadingStrategy*/ {
* include zone to run outside of zone.js
*/
constructor(private _ngZone: NgZone, @Inject(REQUEST_IDLE_CALLBACK) private requestIdleCallback: any) {}
loadingRoute = new Set<Route>();
loading = true;

/*To avoid reloading the route*/
if (this.loadingRoute.has(route)) {
this.loading = false;
}
/*Checking for slow internet connection*/
const conn = typeof navigator !== 'undefined' ? (navigator as any).connection : undefined;
if (conn) {
if ((conn.effectiveType || '').includes('2g') || conn.saveData) { this.loading = false};
}

/*
* fire off preloading async modules
* fire off preloading async modules - loading only required modules
*/
preload(route: /*Route*/ any, fn: any /* () => Observable<any>*/ ): any/* Observable<any> */ {
this.requestIdleCallback(fn);
return of(null);
}

if (this.loading) {
if(route.data && !route.data.preload) {
return null;
} else {
preload(route: /*Route*/ any, fn: any /* () => Observable<any>*/ ): any/* Observable<any> */ {
this.requestIdleCallback(fn);
return of(null);
}
}
}

/*
Expand Down