@ -7,16 +7,8 @@
|
||||
*/
|
||||
|
||||
import {Injector, NgModuleRef} from '@angular/core';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import {Observer} from 'rxjs/Observer';
|
||||
import {from} from 'rxjs/observable/from';
|
||||
import {of } from 'rxjs/observable/of';
|
||||
import {_catch} from 'rxjs/operator/catch';
|
||||
import {concatAll} from 'rxjs/operator/concatAll';
|
||||
import {first} from 'rxjs/operator/first';
|
||||
import {map} from 'rxjs/operator/map';
|
||||
import {mergeMap} from 'rxjs/operator/mergeMap';
|
||||
import {EmptyError} from 'rxjs/util/EmptyError';
|
||||
import {EmptyError, Observable, Observer, from, of } from 'rxjs';
|
||||
import {catchError, concatAll, first, map, mergeMap} from 'rxjs/operators';
|
||||
|
||||
import {LoadedRouterConfig, Route, Routes} from './config';
|
||||
import {RouterConfigLoader} from './router_config_loader';
|
||||
@ -80,10 +72,10 @@ class ApplyRedirects {
|
||||
apply(): Observable<UrlTree> {
|
||||
const expanded$ =
|
||||
this.expandSegmentGroup(this.ngModule, this.config, this.urlTree.root, PRIMARY_OUTLET);
|
||||
const urlTrees$ = map.call(
|
||||
expanded$, (rootSegmentGroup: UrlSegmentGroup) => this.createUrlTree(
|
||||
rootSegmentGroup, this.urlTree.queryParams, this.urlTree.fragment !));
|
||||
return _catch.call(urlTrees$, (e: any) => {
|
||||
const urlTrees$ = expanded$.pipe(
|
||||
map((rootSegmentGroup: UrlSegmentGroup) => this.createUrlTree(
|
||||
rootSegmentGroup, this.urlTree.queryParams, this.urlTree.fragment !)));
|
||||
return urlTrees$.pipe(catchError((e: any) => {
|
||||
if (e instanceof AbsoluteRedirect) {
|
||||
// after an absolute redirect we do not apply any more redirects!
|
||||
this.allowRedirects = false;
|
||||
@ -96,22 +88,22 @@ class ApplyRedirects {
|
||||
}
|
||||
|
||||
throw e;
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
private match(tree: UrlTree): Observable<UrlTree> {
|
||||
const expanded$ =
|
||||
this.expandSegmentGroup(this.ngModule, this.config, tree.root, PRIMARY_OUTLET);
|
||||
const mapped$ = map.call(
|
||||
expanded$, (rootSegmentGroup: UrlSegmentGroup) =>
|
||||
this.createUrlTree(rootSegmentGroup, tree.queryParams, tree.fragment !));
|
||||
return _catch.call(mapped$, (e: any): Observable<UrlTree> => {
|
||||
const mapped$ = expanded$.pipe(
|
||||
map((rootSegmentGroup: UrlSegmentGroup) =>
|
||||
this.createUrlTree(rootSegmentGroup, tree.queryParams, tree.fragment !)));
|
||||
return mapped$.pipe(catchError((e: any): Observable<UrlTree> => {
|
||||
if (e instanceof NoMatch) {
|
||||
throw this.noMatchError(e);
|
||||
}
|
||||
|
||||
throw e;
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
private noMatchError(e: NoMatch): any {
|
||||
@ -130,9 +122,8 @@ class ApplyRedirects {
|
||||
ngModule: NgModuleRef<any>, routes: Route[], segmentGroup: UrlSegmentGroup,
|
||||
outlet: string): Observable<UrlSegmentGroup> {
|
||||
if (segmentGroup.segments.length === 0 && segmentGroup.hasChildren()) {
|
||||
return map.call(
|
||||
this.expandChildren(ngModule, routes, segmentGroup),
|
||||
(children: any) => new UrlSegmentGroup([], children));
|
||||
return this.expandChildren(ngModule, routes, segmentGroup)
|
||||
.pipe(map((children: any) => new UrlSegmentGroup([], children)));
|
||||
}
|
||||
|
||||
return this.expandSegment(ngModule, segmentGroup, routes, segmentGroup.segments, outlet, true);
|
||||
@ -151,31 +142,28 @@ class ApplyRedirects {
|
||||
ngModule: NgModuleRef<any>, segmentGroup: UrlSegmentGroup, routes: Route[],
|
||||
segments: UrlSegment[], outlet: string,
|
||||
allowRedirects: boolean): Observable<UrlSegmentGroup> {
|
||||
const routes$ = of (...routes);
|
||||
const processedRoutes$ = map.call(routes$, (r: any) => {
|
||||
const expanded$ = this.expandSegmentAgainstRoute(
|
||||
ngModule, segmentGroup, routes, r, segments, outlet, allowRedirects);
|
||||
return _catch.call(expanded$, (e: any) => {
|
||||
if (e instanceof NoMatch) {
|
||||
return of (null);
|
||||
}
|
||||
|
||||
throw e;
|
||||
});
|
||||
});
|
||||
const concattedProcessedRoutes$ = concatAll.call(processedRoutes$);
|
||||
const first$ = first.call(concattedProcessedRoutes$, (s: any) => !!s);
|
||||
return _catch.call(first$, (e: any, _: any): Observable<UrlSegmentGroup> => {
|
||||
if (e instanceof EmptyError || e.name === 'EmptyError') {
|
||||
if (this.noLeftoversInUrl(segmentGroup, segments, outlet)) {
|
||||
return of (new UrlSegmentGroup([], {}));
|
||||
}
|
||||
|
||||
throw new NoMatch(segmentGroup);
|
||||
}
|
||||
|
||||
throw e;
|
||||
});
|
||||
return of (...routes).pipe(
|
||||
map((r: any) => {
|
||||
const expanded$ = this.expandSegmentAgainstRoute(
|
||||
ngModule, segmentGroup, routes, r, segments, outlet, allowRedirects);
|
||||
return expanded$.pipe(catchError((e: any) => {
|
||||
if (e instanceof NoMatch) {
|
||||
// TODO(i): this return type doesn't match the declared Observable<UrlSegmentGroup> -
|
||||
// talk to Jason
|
||||
return of (null) as any;
|
||||
}
|
||||
throw e;
|
||||
}));
|
||||
}),
|
||||
concatAll(), first((s: any) => !!s), catchError((e: any, _: any) => {
|
||||
if (e instanceof EmptyError || e.name === 'EmptyError') {
|
||||
if (this.noLeftoversInUrl(segmentGroup, segments, outlet)) {
|
||||
return of (new UrlSegmentGroup([], {}));
|
||||
}
|
||||
throw new NoMatch(segmentGroup);
|
||||
}
|
||||
throw e;
|
||||
}));
|
||||
}
|
||||
|
||||
private noLeftoversInUrl(segmentGroup: UrlSegmentGroup, segments: UrlSegment[], outlet: string):
|
||||
@ -222,10 +210,10 @@ class ApplyRedirects {
|
||||
return absoluteRedirect(newTree);
|
||||
}
|
||||
|
||||
return mergeMap.call(this.lineralizeSegments(route, newTree), (newSegments: UrlSegment[]) => {
|
||||
return this.lineralizeSegments(route, newTree).pipe(mergeMap((newSegments: UrlSegment[]) => {
|
||||
const group = new UrlSegmentGroup(newSegments, {});
|
||||
return this.expandSegment(ngModule, group, routes, newSegments, outlet, false);
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
private expandRegularSegmentAgainstRouteUsingRedirect(
|
||||
@ -241,11 +229,11 @@ class ApplyRedirects {
|
||||
return absoluteRedirect(newTree);
|
||||
}
|
||||
|
||||
return mergeMap.call(this.lineralizeSegments(route, newTree), (newSegments: UrlSegment[]) => {
|
||||
return this.lineralizeSegments(route, newTree).pipe(mergeMap((newSegments: UrlSegment[]) => {
|
||||
return this.expandSegment(
|
||||
ngModule, segmentGroup, routes, newSegments.concat(segments.slice(lastChild)), outlet,
|
||||
false);
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
private matchSegmentAgainstRoute(
|
||||
@ -253,11 +241,11 @@ class ApplyRedirects {
|
||||
segments: UrlSegment[]): Observable<UrlSegmentGroup> {
|
||||
if (route.path === '**') {
|
||||
if (route.loadChildren) {
|
||||
return map.call(
|
||||
this.configLoader.load(ngModule.injector, route), (cfg: LoadedRouterConfig) => {
|
||||
return this.configLoader.load(ngModule.injector, route)
|
||||
.pipe(map((cfg: LoadedRouterConfig) => {
|
||||
route._loadedConfig = cfg;
|
||||
return new UrlSegmentGroup(segments, {});
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
return of (new UrlSegmentGroup(segments, {}));
|
||||
@ -269,7 +257,7 @@ class ApplyRedirects {
|
||||
const rawSlicedSegments = segments.slice(lastChild);
|
||||
const childConfig$ = this.getChildConfig(ngModule, route);
|
||||
|
||||
return mergeMap.call(childConfig$, (routerConfig: LoadedRouterConfig) => {
|
||||
return childConfig$.pipe(mergeMap((routerConfig: LoadedRouterConfig) => {
|
||||
const childModule = routerConfig.module;
|
||||
const childConfig = routerConfig.routes;
|
||||
|
||||
@ -278,8 +266,8 @@ class ApplyRedirects {
|
||||
|
||||
if (slicedSegments.length === 0 && segmentGroup.hasChildren()) {
|
||||
const expanded$ = this.expandChildren(childModule, childConfig, segmentGroup);
|
||||
return map.call(
|
||||
expanded$, (children: any) => new UrlSegmentGroup(consumedSegments, children));
|
||||
return expanded$.pipe(
|
||||
map((children: any) => new UrlSegmentGroup(consumedSegments, children)));
|
||||
}
|
||||
|
||||
if (childConfig.length === 0 && slicedSegments.length === 0) {
|
||||
@ -288,10 +276,10 @@ class ApplyRedirects {
|
||||
|
||||
const expanded$ = this.expandSegment(
|
||||
childModule, segmentGroup, childConfig, slicedSegments, PRIMARY_OUTLET, true);
|
||||
return map.call(
|
||||
expanded$, (cs: UrlSegmentGroup) =>
|
||||
new UrlSegmentGroup(consumedSegments.concat(cs.segments), cs.children));
|
||||
});
|
||||
return expanded$.pipe(
|
||||
map((cs: UrlSegmentGroup) =>
|
||||
new UrlSegmentGroup(consumedSegments.concat(cs.segments), cs.children)));
|
||||
}));
|
||||
}
|
||||
|
||||
private getChildConfig(ngModule: NgModuleRef<any>, route: Route): Observable<LoadedRouterConfig> {
|
||||
@ -306,18 +294,16 @@ class ApplyRedirects {
|
||||
return of (route._loadedConfig);
|
||||
}
|
||||
|
||||
return mergeMap.call(runCanLoadGuard(ngModule.injector, route), (shouldLoad: boolean) => {
|
||||
|
||||
return runCanLoadGuard(ngModule.injector, route).pipe(mergeMap((shouldLoad: boolean) => {
|
||||
if (shouldLoad) {
|
||||
return map.call(
|
||||
this.configLoader.load(ngModule.injector, route), (cfg: LoadedRouterConfig) => {
|
||||
return this.configLoader.load(ngModule.injector, route)
|
||||
.pipe(map((cfg: LoadedRouterConfig) => {
|
||||
route._loadedConfig = cfg;
|
||||
return cfg;
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
return canLoadFails(route);
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
return of (new LoadedRouterConfig([], ngModule));
|
||||
@ -417,10 +403,10 @@ function runCanLoadGuard(moduleInjector: Injector, route: Route): Observable<boo
|
||||
const canLoad = route.canLoad;
|
||||
if (!canLoad || canLoad.length === 0) return of (true);
|
||||
|
||||
const obs = map.call(from(canLoad), (injectionToken: any) => {
|
||||
const obs = from(canLoad).pipe(map((injectionToken: any) => {
|
||||
const guard = moduleInjector.get(injectionToken);
|
||||
return wrapIntoObservable(guard.canLoad ? guard.canLoad(route) : guard(route));
|
||||
});
|
||||
}));
|
||||
|
||||
return andObservables(obs);
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
*/
|
||||
|
||||
import {NgModuleFactory, NgModuleRef, Type} from '@angular/core';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import {Observable} from 'rxjs';
|
||||
import {PRIMARY_OUTLET} from './shared';
|
||||
import {UrlSegment, UrlSegmentGroup} from './url_tree';
|
||||
|
||||
@ -462,4 +462,4 @@ function getFullPath(parentPath: string, currentRoute: Route): string {
|
||||
export function copyConfig(r: Route): Route {
|
||||
const children = r.children && r.children.map(copyConfig);
|
||||
return children ? {...r, children} : {...r};
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {BehaviorSubject} from 'rxjs/BehaviorSubject';
|
||||
import {BehaviorSubject} from 'rxjs';
|
||||
|
||||
import {DetachedRouteHandleInternal, RouteReuseStrategy} from './route_reuse_strategy';
|
||||
import {ActivatedRoute, ActivatedRouteSnapshot, RouterState, RouterStateSnapshot} from './router_state';
|
||||
@ -74,4 +74,4 @@ function createActivatedRoute(c: ActivatedRouteSnapshot) {
|
||||
return new ActivatedRoute(
|
||||
new BehaviorSubject(c.url), new BehaviorSubject(c.params), new BehaviorSubject(c.queryParams),
|
||||
new BehaviorSubject(c.fragment), new BehaviorSubject(c.data), c.outlet, c.component, c);
|
||||
}
|
||||
}
|
||||
|
@ -8,14 +8,15 @@
|
||||
|
||||
import {LocationStrategy} from '@angular/common';
|
||||
import {Attribute, Directive, ElementRef, HostBinding, HostListener, Input, OnChanges, OnDestroy, Renderer2, isDevMode} from '@angular/core';
|
||||
import {Subscription} from 'rxjs/Subscription';
|
||||
import {Subscription} from 'rxjs';
|
||||
|
||||
import {QueryParamsHandling} from '../config';
|
||||
import {NavigationEnd} from '../events';
|
||||
import {NavigationEnd, RouterEvent} from '../events';
|
||||
import {Router} from '../router';
|
||||
import {ActivatedRoute} from '../router_state';
|
||||
import {UrlTree} from '../url_tree';
|
||||
|
||||
|
||||
/**
|
||||
* @whatItDoes Lets you link to specific parts of your app.
|
||||
*
|
||||
@ -184,7 +185,7 @@ export class RouterLinkWithHref implements OnChanges, OnDestroy {
|
||||
constructor(
|
||||
private router: Router, private route: ActivatedRoute,
|
||||
private locationStrategy: LocationStrategy) {
|
||||
this.subscription = router.events.subscribe(s => {
|
||||
this.subscription = router.events.subscribe((s: RouterEvent) => {
|
||||
if (s instanceof NavigationEnd) {
|
||||
this.updateTargetUrlAndHref();
|
||||
}
|
||||
|
@ -7,11 +7,14 @@
|
||||
*/
|
||||
|
||||
import {AfterContentInit, ChangeDetectorRef, ContentChildren, Directive, ElementRef, Input, OnChanges, OnDestroy, QueryList, Renderer2, SimpleChanges} from '@angular/core';
|
||||
import {Subscription} from 'rxjs/Subscription';
|
||||
import {NavigationEnd} from '../events';
|
||||
import {Subscription} from 'rxjs';
|
||||
|
||||
import {NavigationEnd, RouterEvent} from '../events';
|
||||
import {Router} from '../router';
|
||||
|
||||
import {RouterLink, RouterLinkWithHref} from './router_link';
|
||||
|
||||
|
||||
/**
|
||||
* @whatItDoes Lets you add a CSS class to an element when the link's route becomes active.
|
||||
*
|
||||
@ -93,7 +96,7 @@ export class RouterLinkActive implements OnChanges,
|
||||
constructor(
|
||||
private router: Router, private element: ElementRef, private renderer: Renderer2,
|
||||
private cdr: ChangeDetectorRef) {
|
||||
this.subscription = router.events.subscribe(s => {
|
||||
this.subscription = router.events.subscribe((s: RouterEvent) => {
|
||||
if (s instanceof NavigationEnd) {
|
||||
this.update();
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import {Observable} from 'rxjs';
|
||||
|
||||
import {Route} from './config';
|
||||
import {ActivatedRouteSnapshot, RouterStateSnapshot} from './router_state';
|
||||
|
@ -7,16 +7,8 @@
|
||||
*/
|
||||
|
||||
import {Injector} from '@angular/core';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import {from} from 'rxjs/observable/from';
|
||||
import {of } from 'rxjs/observable/of';
|
||||
import {concatMap} from 'rxjs/operator/concatMap';
|
||||
import {every} from 'rxjs/operator/every';
|
||||
import {first} from 'rxjs/operator/first';
|
||||
import {last} from 'rxjs/operator/last';
|
||||
import {map} from 'rxjs/operator/map';
|
||||
import {mergeMap} from 'rxjs/operator/mergeMap';
|
||||
import {reduce} from 'rxjs/operator/reduce';
|
||||
import {Observable, from, of } from 'rxjs';
|
||||
import {concatMap, every, first, last, map, mergeMap, reduce} from 'rxjs/operators';
|
||||
|
||||
import {LoadedRouterConfig, ResolveData, RunGuardsAndResolvers} from './config';
|
||||
import {ActivationStart, ChildActivationStart, Event} from './events';
|
||||
@ -58,17 +50,17 @@ export class PreActivation {
|
||||
return of (true);
|
||||
}
|
||||
const canDeactivate$ = this.runCanDeactivateChecks();
|
||||
return mergeMap.call(
|
||||
canDeactivate$,
|
||||
(canDeactivate: boolean) => canDeactivate ? this.runCanActivateChecks() : of (false));
|
||||
return canDeactivate$.pipe(mergeMap(
|
||||
(canDeactivate: boolean) => canDeactivate ? this.runCanActivateChecks() : of (false)));
|
||||
}
|
||||
|
||||
resolveData(paramsInheritanceStrategy: 'emptyOnly'|'always'): Observable<any> {
|
||||
if (!this.isActivating()) return of (null);
|
||||
const checks$ = from(this.canActivateChecks);
|
||||
const runningChecks$ = concatMap.call(
|
||||
checks$, (check: CanActivate) => this.runResolve(check.route, paramsInheritanceStrategy));
|
||||
return reduce.call(runningChecks$, (_: any, __: any) => _);
|
||||
return from(this.canActivateChecks)
|
||||
.pipe(
|
||||
concatMap(
|
||||
(check: CanActivate) => this.runResolve(check.route, paramsInheritanceStrategy)),
|
||||
reduce((_: any, __: any) => _));
|
||||
}
|
||||
|
||||
isDeactivating(): boolean { return this.canDeactivateChecks.length !== 0; }
|
||||
@ -194,21 +186,21 @@ export class PreActivation {
|
||||
}
|
||||
|
||||
private runCanDeactivateChecks(): Observable<boolean> {
|
||||
const checks$ = from(this.canDeactivateChecks);
|
||||
const runningChecks$ = mergeMap.call(
|
||||
checks$, (check: CanDeactivate) => this.runCanDeactivate(check.component, check.route));
|
||||
return every.call(runningChecks$, (result: boolean) => result === true);
|
||||
return from(this.canDeactivateChecks)
|
||||
.pipe(
|
||||
mergeMap((check: CanDeactivate) => this.runCanDeactivate(check.component, check.route)),
|
||||
every((result: boolean) => result === true));
|
||||
}
|
||||
|
||||
private runCanActivateChecks(): Observable<boolean> {
|
||||
const checks$ = from(this.canActivateChecks);
|
||||
const runningChecks$ = concatMap.call(
|
||||
checks$,
|
||||
(check: CanActivate) => andObservables(from([
|
||||
this.fireChildActivationStart(check.route.parent), this.fireActivationStart(check.route),
|
||||
this.runCanActivateChild(check.path), this.runCanActivate(check.route)
|
||||
])));
|
||||
return every.call(runningChecks$, (result: boolean) => result === true);
|
||||
return from(this.canActivateChecks)
|
||||
.pipe(
|
||||
concatMap((check: CanActivate) => andObservables(from([
|
||||
this.fireChildActivationStart(check.route.parent),
|
||||
this.fireActivationStart(check.route), this.runCanActivateChild(check.path),
|
||||
this.runCanActivate(check.route)
|
||||
]))),
|
||||
every((result: boolean) => result === true));
|
||||
// this.fireChildActivationStart(check.path),
|
||||
}
|
||||
|
||||
@ -245,7 +237,7 @@ export class PreActivation {
|
||||
private runCanActivate(future: ActivatedRouteSnapshot): Observable<boolean> {
|
||||
const canActivate = future.routeConfig ? future.routeConfig.canActivate : null;
|
||||
if (!canActivate || canActivate.length === 0) return of (true);
|
||||
const obs = map.call(from(canActivate), (c: any) => {
|
||||
const obs = from(canActivate).pipe(map((c: any) => {
|
||||
const guard = this.getToken(c, future);
|
||||
let observable: Observable<boolean>;
|
||||
if (guard.canActivate) {
|
||||
@ -253,8 +245,8 @@ export class PreActivation {
|
||||
} else {
|
||||
observable = wrapIntoObservable(guard(future, this.future));
|
||||
}
|
||||
return first.call(observable);
|
||||
});
|
||||
return observable.pipe(first());
|
||||
}));
|
||||
return andObservables(obs);
|
||||
}
|
||||
|
||||
@ -266,8 +258,8 @@ export class PreActivation {
|
||||
.map(p => this.extractCanActivateChild(p))
|
||||
.filter(_ => _ !== null);
|
||||
|
||||
return andObservables(map.call(from(canActivateChildGuards), (d: any) => {
|
||||
const obs = map.call(from(d.guards), (c: any) => {
|
||||
return andObservables(from(canActivateChildGuards).pipe(map((d: any) => {
|
||||
const obs = from(d.guards).pipe(map((c: any) => {
|
||||
const guard = this.getToken(c, d.node);
|
||||
let observable: Observable<boolean>;
|
||||
if (guard.canActivateChild) {
|
||||
@ -275,10 +267,10 @@ export class PreActivation {
|
||||
} else {
|
||||
observable = wrapIntoObservable(guard(future, this.future));
|
||||
}
|
||||
return first.call(observable);
|
||||
});
|
||||
return observable.pipe(first());
|
||||
}));
|
||||
return andObservables(obs);
|
||||
}));
|
||||
})));
|
||||
}
|
||||
|
||||
private extractCanActivateChild(p: ActivatedRouteSnapshot):
|
||||
@ -292,7 +284,7 @@ export class PreActivation {
|
||||
Observable<boolean> {
|
||||
const canDeactivate = curr && curr.routeConfig ? curr.routeConfig.canDeactivate : null;
|
||||
if (!canDeactivate || canDeactivate.length === 0) return of (true);
|
||||
const canDeactivate$ = mergeMap.call(from(canDeactivate), (c: any) => {
|
||||
const canDeactivate$ = from(canDeactivate).pipe(mergeMap((c: any) => {
|
||||
const guard = this.getToken(c, curr);
|
||||
let observable: Observable<boolean>;
|
||||
if (guard.canDeactivate) {
|
||||
@ -301,21 +293,21 @@ export class PreActivation {
|
||||
} else {
|
||||
observable = wrapIntoObservable(guard(component, curr, this.curr, this.future));
|
||||
}
|
||||
return first.call(observable);
|
||||
});
|
||||
return every.call(canDeactivate$, (result: any) => result === true);
|
||||
return observable.pipe(first());
|
||||
}));
|
||||
return canDeactivate$.pipe(every((result: any) => result === true));
|
||||
}
|
||||
|
||||
private runResolve(
|
||||
future: ActivatedRouteSnapshot,
|
||||
paramsInheritanceStrategy: 'emptyOnly'|'always'): Observable<any> {
|
||||
const resolve = future._resolve;
|
||||
return map.call(this.resolveNode(resolve, future), (resolvedData: any): any => {
|
||||
return this.resolveNode(resolve, future).pipe(map((resolvedData: any): any => {
|
||||
future._resolvedData = resolvedData;
|
||||
future.data = {...future.data,
|
||||
...inheritedParamsDataResolve(future, paramsInheritanceStrategy).resolve};
|
||||
return null;
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
private resolveNode(resolve: ResolveData, future: ActivatedRouteSnapshot): Observable<any> {
|
||||
@ -325,17 +317,18 @@ export class PreActivation {
|
||||
}
|
||||
if (keys.length === 1) {
|
||||
const key = keys[0];
|
||||
return map.call(
|
||||
this.getResolver(resolve[key], future), (value: any) => { return {[key]: value}; });
|
||||
return this.getResolver(resolve[key], future).pipe(map((value: any) => {
|
||||
return {[key]: value};
|
||||
}));
|
||||
}
|
||||
const data: {[k: string]: any} = {};
|
||||
const runningResolvers$ = mergeMap.call(from(keys), (key: string) => {
|
||||
return map.call(this.getResolver(resolve[key], future), (value: any) => {
|
||||
const runningResolvers$ = from(keys).pipe(mergeMap((key: string) => {
|
||||
return this.getResolver(resolve[key], future).pipe(map((value: any) => {
|
||||
data[key] = value;
|
||||
return value;
|
||||
});
|
||||
});
|
||||
return map.call(last.call(runningResolvers$), () => data);
|
||||
}));
|
||||
}));
|
||||
return runningResolvers$.pipe(last(), map(() => data));
|
||||
}
|
||||
|
||||
private getResolver(injectionToken: any, future: ActivatedRouteSnapshot): Observable<any> {
|
||||
|
@ -7,9 +7,7 @@
|
||||
*/
|
||||
|
||||
import {Type} from '@angular/core';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import {Observer} from 'rxjs/Observer';
|
||||
import {of } from 'rxjs/observable/of';
|
||||
import {Observable, Observer, of } from 'rxjs';
|
||||
|
||||
import {Data, ResolveData, Route, Routes} from './config';
|
||||
import {ActivatedRouteSnapshot, ParamsInheritanceStrategy, RouterStateSnapshot, inheritedParamsDataResolve} from './router_state';
|
||||
|
@ -8,14 +8,8 @@
|
||||
|
||||
import {Location} from '@angular/common';
|
||||
import {Compiler, Injector, NgModuleFactoryLoader, NgModuleRef, Type, isDevMode} from '@angular/core';
|
||||
import {BehaviorSubject} from 'rxjs/BehaviorSubject';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import {Subject} from 'rxjs/Subject';
|
||||
import {Subscription} from 'rxjs/Subscription';
|
||||
import {of } from 'rxjs/observable/of';
|
||||
import {concatMap} from 'rxjs/operator/concatMap';
|
||||
import {map} from 'rxjs/operator/map';
|
||||
import {mergeMap} from 'rxjs/operator/mergeMap';
|
||||
import {BehaviorSubject, Observable, Subject, Subscription, of } from 'rxjs';
|
||||
import {concatMap, map, mergeMap} from 'rxjs/operators';
|
||||
|
||||
import {applyRedirects} from './apply_redirects';
|
||||
import {LoadedRouterConfig, QueryParamsHandling, Route, Routes, copyConfig, validateConfig} from './config';
|
||||
@ -163,6 +157,9 @@ function defaultErrorHandler(error: any): any {
|
||||
throw error;
|
||||
}
|
||||
|
||||
type NavStreamValue =
|
||||
boolean | {appliedUrl: UrlTree, snapshot: RouterStateSnapshot, shouldActivate?: boolean};
|
||||
|
||||
type NavigationParams = {
|
||||
id: number,
|
||||
rawUrl: UrlTree,
|
||||
@ -511,19 +508,17 @@ export class Router {
|
||||
}
|
||||
|
||||
private processNavigations(): void {
|
||||
concatMap
|
||||
.call(
|
||||
this.navigations,
|
||||
(nav: NavigationParams) => {
|
||||
if (nav) {
|
||||
this.executeScheduledNavigation(nav);
|
||||
// a failed navigation should not stop the router from processing
|
||||
// further navigations => the catch
|
||||
return nav.promise.catch(() => {});
|
||||
} else {
|
||||
return <any>of (null);
|
||||
}
|
||||
})
|
||||
this.navigations
|
||||
.pipe(concatMap((nav: NavigationParams) => {
|
||||
if (nav) {
|
||||
this.executeScheduledNavigation(nav);
|
||||
// a failed navigation should not stop the router from processing
|
||||
// further navigations => the catch
|
||||
return nav.promise.catch(() => {});
|
||||
} else {
|
||||
return <any>of (null);
|
||||
}
|
||||
}))
|
||||
.subscribe(() => {});
|
||||
}
|
||||
|
||||
@ -620,98 +615,101 @@ export class Router {
|
||||
return new Promise((resolvePromise, rejectPromise) => {
|
||||
// create an observable of the url and route state snapshot
|
||||
// this operation do not result in any side effects
|
||||
let urlAndSnapshot$: Observable<{appliedUrl: UrlTree, snapshot: RouterStateSnapshot}>;
|
||||
let urlAndSnapshot$: Observable<NavStreamValue>;
|
||||
if (!precreatedState) {
|
||||
const moduleInjector = this.ngModule.injector;
|
||||
const redirectsApplied$ =
|
||||
applyRedirects(moduleInjector, this.configLoader, this.urlSerializer, url, this.config);
|
||||
|
||||
urlAndSnapshot$ = mergeMap.call(redirectsApplied$, (appliedUrl: UrlTree) => {
|
||||
return map.call(
|
||||
recognize(
|
||||
this.rootComponentType, this.config, appliedUrl, this.serializeUrl(appliedUrl),
|
||||
this.paramsInheritanceStrategy),
|
||||
(snapshot: any) => {
|
||||
|
||||
urlAndSnapshot$ = redirectsApplied$.pipe(mergeMap((appliedUrl: UrlTree) => {
|
||||
return recognize(
|
||||
this.rootComponentType, this.config, appliedUrl, this.serializeUrl(appliedUrl),
|
||||
this.paramsInheritanceStrategy)
|
||||
.pipe(map((snapshot: any) => {
|
||||
(this.events as Subject<Event>)
|
||||
.next(new RoutesRecognized(
|
||||
id, this.serializeUrl(url), this.serializeUrl(appliedUrl), snapshot));
|
||||
|
||||
return {appliedUrl, snapshot};
|
||||
});
|
||||
});
|
||||
}));
|
||||
}));
|
||||
} else {
|
||||
urlAndSnapshot$ = of ({appliedUrl: url, snapshot: precreatedState});
|
||||
}
|
||||
|
||||
const beforePreactivationDone$ = mergeMap.call(
|
||||
urlAndSnapshot$, (p: {appliedUrl: string, snapshot: RouterStateSnapshot}) => {
|
||||
return map.call(this.hooks.beforePreactivation(p.snapshot), () => p);
|
||||
});
|
||||
const beforePreactivationDone$ =
|
||||
urlAndSnapshot$.pipe(mergeMap((p): Observable<NavStreamValue> => {
|
||||
if (typeof p === 'boolean') return of (p);
|
||||
return this.hooks.beforePreactivation(p.snapshot).pipe(map(() => p));
|
||||
}));
|
||||
|
||||
// run preactivation: guards and data resolvers
|
||||
let preActivation: PreActivation;
|
||||
|
||||
const preactivationSetup$ = map.call(
|
||||
beforePreactivationDone$,
|
||||
({appliedUrl, snapshot}: {appliedUrl: string, snapshot: RouterStateSnapshot}) => {
|
||||
const moduleInjector = this.ngModule.injector;
|
||||
preActivation = new PreActivation(
|
||||
snapshot, this.routerState.snapshot, moduleInjector,
|
||||
(evt: Event) => this.triggerEvent(evt));
|
||||
preActivation.initialize(this.rootContexts);
|
||||
return {appliedUrl, snapshot};
|
||||
});
|
||||
const preactivationSetup$ = beforePreactivationDone$.pipe(map((p): NavStreamValue => {
|
||||
if (typeof p === 'boolean') return p;
|
||||
const {appliedUrl, snapshot} = p;
|
||||
const moduleInjector = this.ngModule.injector;
|
||||
preActivation = new PreActivation(
|
||||
snapshot, this.routerState.snapshot, moduleInjector,
|
||||
(evt: Event) => this.triggerEvent(evt));
|
||||
preActivation.initialize(this.rootContexts);
|
||||
return {appliedUrl, snapshot};
|
||||
}));
|
||||
|
||||
const preactivationCheckGuards$ = mergeMap.call(
|
||||
preactivationSetup$,
|
||||
({appliedUrl, snapshot}: {appliedUrl: string, snapshot: RouterStateSnapshot}) => {
|
||||
if (this.navigationId !== id) return of (false);
|
||||
const preactivationCheckGuards$ =
|
||||
preactivationSetup$.pipe(mergeMap((p): Observable<NavStreamValue> => {
|
||||
if (typeof p === 'boolean' || this.navigationId !== id) return of (false);
|
||||
const {appliedUrl, snapshot} = p;
|
||||
|
||||
this.triggerEvent(
|
||||
new GuardsCheckStart(id, this.serializeUrl(url), appliedUrl, snapshot));
|
||||
this.triggerEvent(new GuardsCheckStart(
|
||||
id, this.serializeUrl(url), this.serializeUrl(appliedUrl), snapshot));
|
||||
|
||||
return map.call(preActivation.checkGuards(), (shouldActivate: boolean) => {
|
||||
return preActivation.checkGuards().pipe(map((shouldActivate: boolean) => {
|
||||
this.triggerEvent(new GuardsCheckEnd(
|
||||
id, this.serializeUrl(url), appliedUrl, snapshot, shouldActivate));
|
||||
id, this.serializeUrl(url), this.serializeUrl(appliedUrl), snapshot,
|
||||
shouldActivate));
|
||||
return {appliedUrl: appliedUrl, snapshot: snapshot, shouldActivate: shouldActivate};
|
||||
});
|
||||
});
|
||||
}));
|
||||
}));
|
||||
|
||||
const preactivationResolveData$ = mergeMap.call(
|
||||
preactivationCheckGuards$,
|
||||
(p: {appliedUrl: string, snapshot: RouterStateSnapshot, shouldActivate: boolean}) => {
|
||||
if (this.navigationId !== id) return of (false);
|
||||
const preactivationResolveData$ =
|
||||
preactivationCheckGuards$.pipe(mergeMap((p): Observable<NavStreamValue> => {
|
||||
if (typeof p === 'boolean' || this.navigationId !== id) return of (false);
|
||||
|
||||
if (p.shouldActivate && preActivation.isActivating()) {
|
||||
this.triggerEvent(
|
||||
new ResolveStart(id, this.serializeUrl(url), p.appliedUrl, p.snapshot));
|
||||
return map.call(preActivation.resolveData(this.paramsInheritanceStrategy), () => {
|
||||
this.triggerEvent(
|
||||
new ResolveEnd(id, this.serializeUrl(url), p.appliedUrl, p.snapshot));
|
||||
this.triggerEvent(new ResolveStart(
|
||||
id, this.serializeUrl(url), this.serializeUrl(p.appliedUrl), p.snapshot));
|
||||
return preActivation.resolveData(this.paramsInheritanceStrategy).pipe(map(() => {
|
||||
this.triggerEvent(new ResolveEnd(
|
||||
id, this.serializeUrl(url), this.serializeUrl(p.appliedUrl), p.snapshot));
|
||||
return p;
|
||||
});
|
||||
}));
|
||||
} else {
|
||||
return of (p);
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
||||
const preactivationDone$ = mergeMap.call(preactivationResolveData$, (p: any) => {
|
||||
return map.call(this.hooks.afterPreactivation(p.snapshot), () => p);
|
||||
});
|
||||
const preactivationDone$ =
|
||||
preactivationResolveData$.pipe(mergeMap((p): Observable<NavStreamValue> => {
|
||||
if (typeof p === 'boolean' || this.navigationId !== id) return of (false);
|
||||
return this.hooks.afterPreactivation(p.snapshot).pipe(map(() => p));
|
||||
}));
|
||||
|
||||
|
||||
// create router state
|
||||
// this operation has side effects => route state is being affected
|
||||
const routerState$ =
|
||||
map.call(preactivationDone$, ({appliedUrl, snapshot, shouldActivate}: any) => {
|
||||
if (shouldActivate) {
|
||||
const state = createRouterState(this.routeReuseStrategy, snapshot, this.routerState);
|
||||
return {appliedUrl, state, shouldActivate};
|
||||
} else {
|
||||
return {appliedUrl, state: null, shouldActivate};
|
||||
}
|
||||
});
|
||||
const routerState$ = preactivationDone$.pipe(map((p) => {
|
||||
if (typeof p === 'boolean' || this.navigationId !== id) return false;
|
||||
const {appliedUrl, snapshot, shouldActivate} = p;
|
||||
if (shouldActivate) {
|
||||
const state = createRouterState(this.routeReuseStrategy, snapshot, this.routerState);
|
||||
return {appliedUrl, state, shouldActivate};
|
||||
} else {
|
||||
return {appliedUrl, state: null, shouldActivate};
|
||||
}
|
||||
}));
|
||||
|
||||
|
||||
this.activateRoutes(
|
||||
routerState$, this.routerState, this.currentUrlTree, id, url, rawUrl, skipLocationChange,
|
||||
@ -724,7 +722,8 @@ export class Router {
|
||||
* is a private method, it could be overridden to make activation asynchronous.
|
||||
*/
|
||||
private activateRoutes(
|
||||
state: Observable<{appliedUrl: string, state: RouterState, shouldActivate: boolean}>,
|
||||
state: Observable<false|
|
||||
{appliedUrl: UrlTree, state: RouterState|null, shouldActivate?: boolean}>,
|
||||
storedState: RouterState, storedUrl: UrlTree, id: number, url: UrlTree, rawUrl: UrlTree,
|
||||
skipLocationChange: boolean, replaceUrl: boolean, resolvePromise: any, rejectPromise: any) {
|
||||
// applied the new router state
|
||||
@ -732,12 +731,12 @@ export class Router {
|
||||
let navigationIsSuccessful: boolean;
|
||||
|
||||
state
|
||||
.forEach(({appliedUrl, state, shouldActivate}: any) => {
|
||||
if (!shouldActivate || id !== this.navigationId) {
|
||||
.forEach((p) => {
|
||||
if (typeof p === 'boolean' || !p.shouldActivate || id !== this.navigationId || !p.state) {
|
||||
navigationIsSuccessful = false;
|
||||
return;
|
||||
}
|
||||
|
||||
const {appliedUrl, state} = p;
|
||||
this.currentUrlTree = appliedUrl;
|
||||
this.rawUrlTree = this.urlHandlingStrategy.merge(this.currentUrlTree, rawUrl);
|
||||
|
||||
|
@ -6,12 +6,10 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {Compiler, InjectionToken, Injector, NgModuleFactory, NgModuleFactoryLoader, NgModuleRef} from '@angular/core';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import {fromPromise} from 'rxjs/observable/fromPromise';
|
||||
import {of } from 'rxjs/observable/of';
|
||||
import {map} from 'rxjs/operator/map';
|
||||
import {mergeMap} from 'rxjs/operator/mergeMap';
|
||||
import {Compiler, InjectionToken, Injector, NgModuleFactory, NgModuleFactoryLoader} from '@angular/core';
|
||||
// TODO(i): switch to fromPromise once it's expored in rxjs
|
||||
import {Observable, from, of } from 'rxjs';
|
||||
import {map, mergeMap} from 'rxjs/operators';
|
||||
import {LoadChildren, LoadedRouterConfig, Route, copyConfig} from './config';
|
||||
import {flatten, wrapIntoObservable} from './utils/collection';
|
||||
|
||||
@ -34,7 +32,7 @@ export class RouterConfigLoader {
|
||||
|
||||
const moduleFactory$ = this.loadModuleFactory(route.loadChildren !);
|
||||
|
||||
return map.call(moduleFactory$, (factory: NgModuleFactory<any>) => {
|
||||
return moduleFactory$.pipe(map((factory: NgModuleFactory<any>) => {
|
||||
if (this.onLoadEndListener) {
|
||||
this.onLoadEndListener(route);
|
||||
}
|
||||
@ -42,20 +40,20 @@ export class RouterConfigLoader {
|
||||
const module = factory.create(parentInjector);
|
||||
|
||||
return new LoadedRouterConfig(flatten(module.injector.get(ROUTES)).map(copyConfig), module);
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
private loadModuleFactory(loadChildren: LoadChildren): Observable<NgModuleFactory<any>> {
|
||||
if (typeof loadChildren === 'string') {
|
||||
return fromPromise(this.loader.load(loadChildren));
|
||||
return from(this.loader.load(loadChildren));
|
||||
} else {
|
||||
return mergeMap.call(wrapIntoObservable(loadChildren()), (t: any) => {
|
||||
return wrapIntoObservable(loadChildren()).pipe(mergeMap((t: any) => {
|
||||
if (t instanceof NgModuleFactory) {
|
||||
return of (t);
|
||||
} else {
|
||||
return fromPromise(this.compiler.compileModuleAsync(t));
|
||||
return from(this.compiler.compileModuleAsync(t));
|
||||
}
|
||||
});
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,13 +9,13 @@
|
||||
import {APP_BASE_HREF, HashLocationStrategy, LOCATION_INITIALIZED, Location, LocationStrategy, PathLocationStrategy, PlatformLocation} from '@angular/common';
|
||||
import {ANALYZE_FOR_ENTRY_COMPONENTS, APP_BOOTSTRAP_LISTENER, APP_INITIALIZER, ApplicationRef, Compiler, ComponentRef, Inject, Injectable, InjectionToken, Injector, ModuleWithProviders, NgModule, NgModuleFactoryLoader, NgProbeToken, Optional, Provider, SkipSelf, SystemJsNgModuleLoader} from '@angular/core';
|
||||
import {ɵgetDOM as getDOM} from '@angular/platform-browser';
|
||||
import {Subject} from 'rxjs/Subject';
|
||||
import {of } from 'rxjs/observable/of';
|
||||
import {Subject, of } from 'rxjs';
|
||||
|
||||
import {Route, Routes} from './config';
|
||||
import {RouterLink, RouterLinkWithHref} from './directives/router_link';
|
||||
import {RouterLinkActive} from './directives/router_link_active';
|
||||
import {RouterOutlet} from './directives/router_outlet';
|
||||
import {RouterEvent} from './events';
|
||||
import {RouteReuseStrategy} from './route_reuse_strategy';
|
||||
import {ErrorHandler, Router} from './router';
|
||||
import {ROUTES} from './router_config_loader';
|
||||
@ -27,6 +27,7 @@ import {DefaultUrlSerializer, UrlSerializer} from './url_tree';
|
||||
import {flatten} from './utils/collection';
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @whatItDoes Contains a list of directives
|
||||
* @stable
|
||||
@ -312,7 +313,7 @@ export function setupRouter(
|
||||
|
||||
if (opts.enableTracing) {
|
||||
const dom = getDOM();
|
||||
router.events.subscribe(e => {
|
||||
router.events.subscribe((e: RouterEvent) => {
|
||||
dom.logGroup(`Router Event: ${(<any>e.constructor).name}`);
|
||||
dom.log(e.toString());
|
||||
dom.log(e);
|
||||
|
@ -7,20 +7,15 @@
|
||||
*/
|
||||
|
||||
import {Compiler, Injectable, Injector, NgModuleFactoryLoader, NgModuleRef, OnDestroy} from '@angular/core';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import {Subscription} from 'rxjs/Subscription';
|
||||
import {from} from 'rxjs/observable/from';
|
||||
import {of } from 'rxjs/observable/of';
|
||||
import {_catch} from 'rxjs/operator/catch';
|
||||
import {concatMap} from 'rxjs/operator/concatMap';
|
||||
import {filter} from 'rxjs/operator/filter';
|
||||
import {mergeAll} from 'rxjs/operator/mergeAll';
|
||||
import {mergeMap} from 'rxjs/operator/mergeMap';
|
||||
import {Observable, Subscription, from, of } from 'rxjs';
|
||||
import {catchError, concatMap, filter, map, mergeAll, mergeMap} from 'rxjs/operators';
|
||||
|
||||
import {LoadedRouterConfig, Route, Routes} from './config';
|
||||
import {Event, NavigationEnd, RouteConfigLoadEnd, RouteConfigLoadStart} from './events';
|
||||
import {Router} from './router';
|
||||
import {RouterConfigLoader} from './router_config_loader';
|
||||
|
||||
|
||||
/**
|
||||
* @whatItDoes Provides a preloading strategy.
|
||||
*
|
||||
@ -43,7 +38,7 @@ export abstract class PreloadingStrategy {
|
||||
*/
|
||||
export class PreloadAllModules implements PreloadingStrategy {
|
||||
preload(route: Route, fn: () => Observable<any>): Observable<any> {
|
||||
return _catch.call(fn(), () => of (null));
|
||||
return fn().pipe(catchError(() => of (null)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -87,8 +82,10 @@ export class RouterPreloader implements OnDestroy {
|
||||
}
|
||||
|
||||
setUpPreloading(): void {
|
||||
const navigations$ = filter.call(this.router.events, (e: Event) => e instanceof NavigationEnd);
|
||||
this.subscription = concatMap.call(navigations$, () => this.preload()).subscribe(() => {});
|
||||
this.subscription =
|
||||
this.router.events
|
||||
.pipe(filter((e: Event) => e instanceof NavigationEnd), concatMap(() => this.preload()))
|
||||
.subscribe(() => {});
|
||||
}
|
||||
|
||||
preload(): Observable<any> {
|
||||
@ -118,16 +115,16 @@ export class RouterPreloader implements OnDestroy {
|
||||
res.push(this.processRoutes(ngModule, route.children));
|
||||
}
|
||||
}
|
||||
return mergeAll.call(from(res));
|
||||
return from(res).pipe(mergeAll(), map((_) => void 0));
|
||||
}
|
||||
|
||||
private preloadConfig(ngModule: NgModuleRef<any>, route: Route): Observable<void> {
|
||||
return this.preloadingStrategy.preload(route, () => {
|
||||
const loaded$ = this.loader.load(ngModule.injector, route);
|
||||
return mergeMap.call(loaded$, (config: LoadedRouterConfig) => {
|
||||
return loaded$.pipe(mergeMap((config: LoadedRouterConfig) => {
|
||||
route._loadedConfig = config;
|
||||
return this.processRoutes(config.module, config.routes);
|
||||
});
|
||||
}));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -7,9 +7,8 @@
|
||||
*/
|
||||
|
||||
import {Type} from '@angular/core';
|
||||
import {BehaviorSubject} from 'rxjs/BehaviorSubject';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import {map} from 'rxjs/operator/map';
|
||||
import {BehaviorSubject, Observable} from 'rxjs';
|
||||
import {map} from 'rxjs/operators';
|
||||
|
||||
import {Data, ResolveData, Route} from './config';
|
||||
import {PRIMARY_OUTLET, ParamMap, Params, convertToParamMap} from './shared';
|
||||
@ -157,7 +156,7 @@ export class ActivatedRoute {
|
||||
|
||||
get paramMap(): Observable<ParamMap> {
|
||||
if (!this._paramMap) {
|
||||
this._paramMap = map.call(this.params, (p: Params): ParamMap => convertToParamMap(p));
|
||||
this._paramMap = this.params.pipe(map((p: Params): ParamMap => convertToParamMap(p)));
|
||||
}
|
||||
return this._paramMap;
|
||||
}
|
||||
@ -165,7 +164,7 @@ export class ActivatedRoute {
|
||||
get queryParamMap(): Observable<ParamMap> {
|
||||
if (!this._queryParamMap) {
|
||||
this._queryParamMap =
|
||||
map.call(this.queryParams, (p: Params): ParamMap => convertToParamMap(p));
|
||||
this.queryParams.pipe(map((p: Params): ParamMap => convertToParamMap(p)));
|
||||
}
|
||||
return this._queryParamMap;
|
||||
}
|
||||
|
@ -7,14 +7,9 @@
|
||||
*/
|
||||
|
||||
import {NgModuleFactory, ɵisObservable as isObservable, ɵisPromise as isPromise} from '@angular/core';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import {fromPromise} from 'rxjs/observable/fromPromise';
|
||||
import {of } from 'rxjs/observable/of';
|
||||
import {concatAll} from 'rxjs/operator/concatAll';
|
||||
import {every} from 'rxjs/operator/every';
|
||||
import * as l from 'rxjs/operator/last';
|
||||
import {map} from 'rxjs/operator/map';
|
||||
import {mergeAll} from 'rxjs/operator/mergeAll';
|
||||
import {Observable, from, of } from 'rxjs';
|
||||
import {concatAll, every, last as lastValue, map, mergeAll} from 'rxjs/operators';
|
||||
|
||||
import {PRIMARY_OUTLET} from '../shared';
|
||||
|
||||
export function shallowEqualArrays(a: any[], b: any[]): boolean {
|
||||
@ -81,7 +76,7 @@ export function waitForMap<A, B>(
|
||||
const res: {[k: string]: B} = {};
|
||||
|
||||
forEach(obj, (a: A, k: string) => {
|
||||
const mapped = map.call(fn(k, a), (r: B) => res[k] = r);
|
||||
const mapped = fn(k, a).pipe(map((r: B) => res[k] = r));
|
||||
if (k === PRIMARY_OUTLET) {
|
||||
waitHead.push(mapped);
|
||||
} else {
|
||||
@ -89,9 +84,7 @@ export function waitForMap<A, B>(
|
||||
}
|
||||
});
|
||||
|
||||
const concat$ = concatAll.call(of (...waitHead, ...waitTail));
|
||||
const last$ = l.last.call(concat$);
|
||||
return map.call(last$, () => res);
|
||||
return of (...waitHead, ...waitTail).pipe(concatAll(), lastValue(), map(() => res));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -99,8 +92,7 @@ export function waitForMap<A, B>(
|
||||
* input Observables return `true`.
|
||||
*/
|
||||
export function andObservables(observables: Observable<Observable<any>>): Observable<boolean> {
|
||||
const merged$ = mergeAll.call(observables);
|
||||
return every.call(merged$, (result: any) => result === true);
|
||||
return observables.pipe(mergeAll(), every((result: any) => result === true));
|
||||
}
|
||||
|
||||
export function wrapIntoObservable<T>(value: T | NgModuleFactory<T>| Promise<T>| Observable<T>):
|
||||
@ -113,7 +105,7 @@ export function wrapIntoObservable<T>(value: T | NgModuleFactory<T>| Promise<T>|
|
||||
// Use `Promise.resolve()` to wrap promise-like instances.
|
||||
// Required ie when a Resolver returns a AngularJS `$q` promise to correctly trigger the
|
||||
// change detection.
|
||||
return fromPromise(Promise.resolve(value));
|
||||
return from(Promise.resolve(value));
|
||||
}
|
||||
|
||||
return of (value as T);
|
||||
|
Reference in New Issue
Block a user