feat(router): allow guards to return UrlTree as well as boolean (#26521)

* Removed `andObservable` helper function in favor of inline implementation
* Flow `boolean | UrlTree` through guards check
* Add tests to verify behavior of `checkGuards` function flowing `UrlTree` properly

PR Close #26521
This commit is contained in:
Jason Aden
2018-10-16 19:50:48 -07:00
committed by Matias Niemelä
parent 152ca66eba
commit 081f95c812
7 changed files with 213 additions and 77 deletions

View File

@ -8,7 +8,7 @@
import {NgModuleFactory, ɵisObservable as isObservable, ɵisPromise as isPromise} from '@angular/core';
import {Observable, from, of } from 'rxjs';
import {concatAll, every, last as lastValue, map, mergeAll} from 'rxjs/operators';
import {concatAll, last as lastValue, map} from 'rxjs/operators';
import {PRIMARY_OUTLET} from '../shared';
@ -88,14 +88,6 @@ export function waitForMap<A, B>(
return of .apply(null, waitHead.concat(waitTail)).pipe(concatAll(), lastValue(), map(() => res));
}
/**
* ANDs Observables by merging all input observables, reducing to an Observable verifying all
* input Observables return `true`.
*/
export function andObservables(observables: Observable<Observable<any>>): Observable<boolean> {
return observables.pipe(mergeAll(), every((result: any) => result === true));
}
export function wrapIntoObservable<T>(value: T | NgModuleFactory<T>| Promise<T>| Observable<T>) {
if (isObservable(value)) {
return value;

View File

@ -6,7 +6,6 @@
* found in the LICENSE file at https://angular.io/license
*/
import {Type} from '@angular/core';
import {CanActivate, CanActivateChild, CanDeactivate, CanLoad} from '../interfaces';
/**
@ -26,6 +25,10 @@ export function isFunction<T>(v: any): v is T {
return typeof v === 'function';
}
export function isBoolean(v: any): v is boolean {
return typeof v === 'boolean';
}
export function isCanLoad(guard: any): guard is CanLoad {
return guard && isFunction<CanLoad>(guard.canLoad);
}