refactor(router): misc refactoring
This commit is contained in:
parent
4054055d0d
commit
886cca028f
|
@ -18,8 +18,8 @@ import {map} from 'rxjs/operator/map';
|
|||
import {mergeMap} from 'rxjs/operator/mergeMap';
|
||||
import {EmptyError} from 'rxjs/util/EmptyError';
|
||||
|
||||
import {InternalRoute, Route, Routes} from './config';
|
||||
import {LoadedRouterConfig, RouterConfigLoader} from './router_config_loader';
|
||||
import {InternalRoute, LoadedRouterConfig, Route, Routes} from './config';
|
||||
import {RouterConfigLoader} from './router_config_loader';
|
||||
import {PRIMARY_OUTLET, Params, defaultUrlMatcher, navigationCancelingError} from './shared';
|
||||
import {UrlSegment, UrlSegmentGroup, UrlSerializer, UrlTree} from './url_tree';
|
||||
import {andObservables, forEach, waitForMap, wrapIntoObservable} from './utils/collection';
|
||||
|
|
|
@ -6,13 +6,11 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {NgModuleFactory, Type} from '@angular/core';
|
||||
import {NgModuleFactory, NgModuleRef, Type} from '@angular/core';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
|
||||
import {PRIMARY_OUTLET} from './shared';
|
||||
import {UrlSegment, UrlSegmentGroup} from './url_tree';
|
||||
|
||||
|
||||
/**
|
||||
* @whatItDoes Represents router configuration.
|
||||
*
|
||||
|
@ -359,11 +357,17 @@ export interface Route {
|
|||
children?: Routes;
|
||||
loadChildren?: LoadChildren;
|
||||
runGuardsAndResolvers?: RunGuardsAndResolvers;
|
||||
/** @internal */
|
||||
_loadedConfig?: LoadedRouterConfig;
|
||||
}
|
||||
|
||||
export class LoadedRouterConfig {
|
||||
constructor(public routes: Route[], public module: NgModuleRef<any>) {}
|
||||
}
|
||||
|
||||
export interface InternalRoute extends Route {
|
||||
// `LoadedRouterConfig` loaded via a Route `loadChildren`
|
||||
_loadedConfig?: any;
|
||||
_loadedConfig?: LoadedRouterConfig;
|
||||
}
|
||||
|
||||
export function validateConfig(config: Routes, parentPath: string = ''): void {
|
||||
|
|
|
@ -22,14 +22,14 @@ import {mergeMap} from 'rxjs/operator/mergeMap';
|
|||
import {reduce} from 'rxjs/operator/reduce';
|
||||
|
||||
import {applyRedirects} from './apply_redirects';
|
||||
import {InternalRoute, QueryParamsHandling, ResolveData, Route, Routes, RunGuardsAndResolvers, validateConfig} from './config';
|
||||
import {InternalRoute, LoadedRouterConfig, QueryParamsHandling, ResolveData, Route, Routes, RunGuardsAndResolvers, validateConfig} from './config';
|
||||
import {createRouterState} from './create_router_state';
|
||||
import {createUrlTree} from './create_url_tree';
|
||||
import {RouterOutlet} from './directives/router_outlet';
|
||||
import {Event, NavigationCancel, NavigationEnd, NavigationError, NavigationStart, RouteConfigLoadEnd, RouteConfigLoadStart, RoutesRecognized} from './events';
|
||||
import {recognize} from './recognize';
|
||||
import {DetachedRouteHandle, DetachedRouteHandleInternal, RouteReuseStrategy} from './route_reuse_strategy';
|
||||
import {LoadedRouterConfig, RouterConfigLoader} from './router_config_loader';
|
||||
import {RouterConfigLoader} from './router_config_loader';
|
||||
import {RouterOutletMap} from './router_outlet_map';
|
||||
import {ActivatedRoute, ActivatedRouteSnapshot, RouterState, RouterStateSnapshot, advanceActivatedRoute, createEmptyState, equalParamsAndUrlSegments, inheritedParamsDataResolve} from './router_state';
|
||||
import {PRIMARY_OUTLET, Params, isNavigationCancelingError} from './shared';
|
||||
|
|
|
@ -12,7 +12,7 @@ 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 {LoadChildren, Route} from './config';
|
||||
import {LoadChildren, LoadedRouterConfig, Route} from './config';
|
||||
import {flatten, wrapIntoObservable} from './utils/collection';
|
||||
|
||||
/**
|
||||
|
@ -21,10 +21,6 @@ import {flatten, wrapIntoObservable} from './utils/collection';
|
|||
*/
|
||||
export const ROUTES = new InjectionToken<Route[][]>('ROUTES');
|
||||
|
||||
export class LoadedRouterConfig {
|
||||
constructor(public routes: Route[], public module: NgModuleRef<any>) {}
|
||||
}
|
||||
|
||||
export class RouterConfigLoader {
|
||||
constructor(
|
||||
private loader: NgModuleFactoryLoader, private compiler: Compiler,
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
*found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {Compiler, Injectable, Injector, NgModuleFactoryLoader, NgModuleRef} from '@angular/core';
|
||||
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';
|
||||
|
@ -16,8 +16,8 @@ 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 {InternalRoute, Route, Routes} from './config';
|
||||
import {NavigationEnd, RouteConfigLoadEnd, RouteConfigLoadStart} from './events';
|
||||
import {InternalRoute, LoadedRouterConfig, Route, Routes} from './config';
|
||||
import {Event, NavigationEnd, RouteConfigLoadEnd, RouteConfigLoadStart} from './events';
|
||||
import {Router} from './router';
|
||||
import {RouterConfigLoader} from './router_config_loader';
|
||||
|
||||
|
@ -73,7 +73,7 @@ export class NoPreloading implements PreloadingStrategy {
|
|||
* @stable
|
||||
*/
|
||||
@Injectable()
|
||||
export class RouterPreloader {
|
||||
export class RouterPreloader implements OnDestroy {
|
||||
private loader: RouterConfigLoader;
|
||||
private subscription: Subscription;
|
||||
|
||||
|
@ -87,8 +87,8 @@ export class RouterPreloader {
|
|||
};
|
||||
|
||||
setUpPreloading(): void {
|
||||
const navigations = filter.call(this.router.events, (e: any) => e instanceof NavigationEnd);
|
||||
this.subscription = concatMap.call(navigations, () => this.preload()).subscribe(() => {});
|
||||
const navigations$ = filter.call(this.router.events, (e: Event) => e instanceof NavigationEnd);
|
||||
this.subscription = concatMap.call(navigations$, () => this.preload()).subscribe(() => {});
|
||||
}
|
||||
|
||||
preload(): Observable<any> {
|
||||
|
@ -121,8 +121,8 @@ export class RouterPreloader {
|
|||
|
||||
private preloadConfig(ngModule: NgModuleRef<any>, route: InternalRoute): Observable<void> {
|
||||
return this.preloadingStrategy.preload(route, () => {
|
||||
const loaded = this.loader.load(ngModule.injector, route);
|
||||
return mergeMap.call(loaded, (config: any): any => {
|
||||
const loaded$ = this.loader.load(ngModule.injector, route);
|
||||
return mergeMap.call(loaded$, (config: LoadedRouterConfig) => {
|
||||
route._loadedConfig = config;
|
||||
return this.processRoutes(config.module, config.routes);
|
||||
});
|
||||
|
|
|
@ -12,8 +12,7 @@ import {Observable} from 'rxjs/Observable';
|
|||
import {of } from 'rxjs/observable/of';
|
||||
|
||||
import {applyRedirects} from '../src/apply_redirects';
|
||||
import {Routes} from '../src/config';
|
||||
import {LoadedRouterConfig} from '../src/router_config_loader';
|
||||
import {LoadedRouterConfig, Routes} from '../src/config';
|
||||
import {DefaultUrlSerializer, UrlSegmentGroup, UrlTree, equalSegments} from '../src/url_tree';
|
||||
|
||||
describe('applyRedirects', () => {
|
||||
|
|
|
@ -354,7 +354,7 @@ export declare class RouterOutletMap {
|
|||
}
|
||||
|
||||
/** @stable */
|
||||
export declare class RouterPreloader {
|
||||
export declare class RouterPreloader implements OnDestroy {
|
||||
constructor(router: Router, moduleLoader: NgModuleFactoryLoader, compiler: Compiler, injector: Injector, preloadingStrategy: PreloadingStrategy);
|
||||
ngOnDestroy(): void;
|
||||
preload(): Observable<any>;
|
||||
|
|
Loading…
Reference in New Issue