refactor(router): create pipeable setupPreactivation function (#25740)
PR Close #25740
This commit is contained in:
parent
ef5338663d
commit
9c1c945489
|
@ -0,0 +1,30 @@
|
|||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {Injector} from '@angular/core';
|
||||
import {Observable, OperatorFunction} from 'rxjs';
|
||||
import {map} from 'rxjs/operators';
|
||||
|
||||
import {Event} from '../events';
|
||||
import {PreActivation} from '../pre_activation';
|
||||
import {ChildrenOutletContexts} from '../router_outlet_context';
|
||||
import {RouterStateSnapshot} from '../router_state';
|
||||
|
||||
export function setupPreactivation(
|
||||
rootContexts: ChildrenOutletContexts, currentSnapshot: RouterStateSnapshot,
|
||||
moduleInjector: Injector,
|
||||
forwardEvent?: (evt: Event) => void): OperatorFunction<RouterStateSnapshot, PreActivation> {
|
||||
return function(source: Observable<RouterStateSnapshot>) {
|
||||
return source.pipe(map(snapshot => {
|
||||
const preActivation =
|
||||
new PreActivation(snapshot, currentSnapshot, moduleInjector, forwardEvent);
|
||||
preActivation.initialize(rootContexts);
|
||||
return preActivation;
|
||||
}));
|
||||
};
|
||||
}
|
|
@ -18,6 +18,7 @@ import {ActivationEnd, ChildActivationEnd, Event, GuardsCheckEnd, GuardsCheckSta
|
|||
import {applyRedirects} from './operators/apply_redirects';
|
||||
import {beforePreactivation} from './operators/before_preactivation';
|
||||
import {recognize} from './operators/recognize';
|
||||
import {setupPreactivation} from './operators/setup_preactivation';
|
||||
import {PreActivation} from './pre_activation';
|
||||
import {DefaultRouteReuseStrategy, DetachedRouteHandleInternal, RouteReuseStrategy} from './route_reuse_strategy';
|
||||
import {RouterConfigLoader} from './router_config_loader';
|
||||
|
@ -724,16 +725,15 @@ export class Router {
|
|||
// run preactivation: guards and data resolvers
|
||||
let preActivation: PreActivation;
|
||||
|
||||
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 preactivationSetup$ = beforePreactivationDone$.pipe(
|
||||
mergeMap(
|
||||
p => of (p.snapshot)
|
||||
.pipe(
|
||||
setupPreactivation(
|
||||
this.rootContexts, this.routerState.snapshot, this.ngModule.injector,
|
||||
(evt: Event) => this.triggerEvent(evt)),
|
||||
map(preActivation => ({...p, preActivation})))),
|
||||
tap(p => preActivation = p.preActivation));
|
||||
|
||||
const preactivationCheckGuards$ =
|
||||
preactivationSetup$.pipe(mergeMap((p): Observable<NavStreamValue> => {
|
||||
|
|
Loading…
Reference in New Issue