Skip to content

Instantly share code, notes, and snippets.

@adrianfaciu
Last active December 27, 2019 20:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adrianfaciu/33fb44d7af5909d8dbfacd27c57352e3 to your computer and use it in GitHub Desktop.
Save adrianfaciu/33fb44d7af5909d8dbfacd27c57352e3 to your computer and use it in GitHub Desktop.
export class AppPreloadingStrategy implements PreloadingStrategy {
preload(route: Route, load: Function): Observable<any> {
const loadRoute = (delay) => delay
? timer(150).pipe(flatMap(_ => load()))
: load();
return route.data && route.data.preload
? loadRoute(route.data.delay)
: of(null);
}
}
@joelsulca
Copy link

Where do I gettimer, flatMap, and of from? I've not worked with these before and I see no import statement.

rxjs? lodash?

May I recommend when making example code, please use universally understood code without extra implicit code

import {PreloadingStrategy, Route} from '@angular/router';
import {Observable, of, timer} from 'rxjs';
import {flatMap} from 'rxjs/operators';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment