This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const INITIAL_VALUE = Symbol('INITIAL_VALUE'); | |
declare type INTERIM_VALUES = typeof INITIAL_VALUE | boolean | UrlTree; | |
export function prioritizedGuardValue(): | |
OperatorFunction<Observable<boolean|UrlTree>[], boolean|UrlTree> { | |
return switchMap(obs => { | |
return combineLatest( | |
...obs.map(o => o.pipe(take(1), startWith(INITIAL_VALUE as INTERIM_VALUES)))) | |
.pipe( | |
scan( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private setupNavigations(transitions: Observable<NavigationTransition>): Observable<NavigationTransition> { | |
return transitions.pipe( | |
filter(t => t.id !== 0), | |
// Extract URL | |
map(t => ({...t, extractedUrl: this.urlHandlingStrategy.extract(t.rawUrl)}) as NavigationTransition), | |
// Using switchMap so we cancel executing navigations when a new one comes in | |
switchMap(t => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ path: 'redir', | |
canActivate: [CanActivateRouteGuard, CanActivateRouteGuard2], | |
children: [{ | |
path: 'dir', | |
component: NeverGetHereComponent, | |
canActivate: [ChildCanActivateRouteGuard] | |
}] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ROUTES: Route[] = [ | |
{ path: 'target', component: TargetComponent }, | |
{ path: 'redir', component: NeverGetHereComponent, canActivate: [CanActivateRouteGuard] } | |
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable } from '@angular/core'; | |
import { CanActivate, | |
ActivatedRouteSnapshot, | |
RouterStateSnapshot, | |
Router, | |
UrlTree } from '@angular/router'; | |
@Injectable() | |
export class CanActivateRouteGuard implements CanActivate { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const pipe = (...fns) => initialVal => fns.reduce((g,f) => f(g), initialVal); | |
const add1 = x => x + 1; | |
const mul2 = x => x * 2; | |
const res = pipe(add1,mul2)(0); // mul2(add1(0)) === 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
subscribe(observerOrNext?: PartialObserver<T> | ((value: T) => void), | |
error?: (error: any) => void, | |
complete?: () => void): Subscription { | |
const { operator } = this; | |
const sink = toSubscriber(observerOrNext, error, complete); | |
if (operator) { | |
operator.call(sink, this.source); | |
} else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
setUpPreloading(): void { | |
this.subscription = | |
this.router.events | |
.pipe(filter((e: Event) => e instanceof NavigationEnd), concatMap(() => this.preload())) | |
.subscribe(() => {}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RouterModule.forRoot(ROUTES, { | |
preloadingStrategy: CustomPreloadingStrategy | PreloadAllModules | NoPreloading | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
return this.configLoader.load(ngModule.injector, route) | |
.pipe(map((cfg: LoadedRouterConfig) => { | |
route._loadedConfig = cfg; | |
return cfg; | |
})); |