cleanup(router): clang-format
This commit is contained in:
parent
9de56481f1
commit
2982892acc
@ -7,9 +7,7 @@ import {RouterOutletMap} from './router_outlet_map';
|
|||||||
import {ActivatedRoute} from './router_state';
|
import {ActivatedRoute} from './router_state';
|
||||||
import {DefaultUrlSerializer, UrlSerializer} from './url_serializer';
|
import {DefaultUrlSerializer, UrlSerializer} from './url_serializer';
|
||||||
|
|
||||||
export interface ExtraOptions {
|
export interface ExtraOptions { enableTracing?: boolean; }
|
||||||
enableTracing?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A list of {@link Provider}s. To use the router, you must add this to your application.
|
* A list of {@link Provider}s. To use the router, you must add this to your application.
|
||||||
@ -31,8 +29,7 @@ export interface ExtraOptions {
|
|||||||
*/
|
*/
|
||||||
export function provideRouter(config: RouterConfig, opts: ExtraOptions): any[] {
|
export function provideRouter(config: RouterConfig, opts: ExtraOptions): any[] {
|
||||||
return [
|
return [
|
||||||
Location,
|
Location, {provide: LocationStrategy, useClass: PathLocationStrategy},
|
||||||
{provide: LocationStrategy, useClass: PathLocationStrategy},
|
|
||||||
{provide: UrlSerializer, useClass: DefaultUrlSerializer},
|
{provide: UrlSerializer, useClass: DefaultUrlSerializer},
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -76,10 +73,10 @@ export function provideRouter(config: RouterConfig, opts: ExtraOptions): any[] {
|
|||||||
const appRef = injector.get(ApplicationRef);
|
const appRef = injector.get(ApplicationRef);
|
||||||
if (appRef.componentTypes.length == 0) {
|
if (appRef.componentTypes.length == 0) {
|
||||||
appRef.registerBootstrapListener((_) => {
|
appRef.registerBootstrapListener((_) => {
|
||||||
injector.get(Router).initialNavigation()
|
injector.get(Router).initialNavigation();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
injector.get(Router).initialNavigation()
|
injector.get(Router).initialNavigation();
|
||||||
}
|
}
|
||||||
}, 0);
|
}, 0);
|
||||||
return _ => null;
|
return _ => null;
|
||||||
|
@ -36,8 +36,8 @@ export class RouterOutlet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
activate(
|
activate(
|
||||||
factory: ComponentFactory<any>, activatedRoute: ActivatedRoute, providers: ResolvedReflectiveProvider[],
|
factory: ComponentFactory<any>, activatedRoute: ActivatedRoute,
|
||||||
outletMap: RouterOutletMap): void {
|
providers: ResolvedReflectiveProvider[], outletMap: RouterOutletMap): void {
|
||||||
this.outletMap = outletMap;
|
this.outletMap = outletMap;
|
||||||
this._activatedRoute = activatedRoute;
|
this._activatedRoute = activatedRoute;
|
||||||
const inj = ReflectiveInjector.fromResolvedProviders(providers, this.location.parentInjector);
|
const inj = ReflectiveInjector.fromResolvedProviders(providers, this.location.parentInjector);
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
import {RouterLink} from './directives/router_link';
|
import {RouterLink} from './directives/router_link';
|
||||||
import {RouterOutlet} from './directives/router_outlet';
|
import {RouterOutlet} from './directives/router_outlet';
|
||||||
|
|
||||||
|
export {ExtraOptions} from './common_router_providers';
|
||||||
export {Route, RouterConfig} from './config';
|
export {Route, RouterConfig} from './config';
|
||||||
export {CanActivate, CanDeactivate} from './interfaces';
|
export {CanActivate, CanDeactivate} from './interfaces';
|
||||||
export {Event, NavigationCancel, NavigationEnd, NavigationError, NavigationStart, RoutesRecognized, Router} from './router';
|
export {Event, NavigationCancel, NavigationEnd, NavigationError, NavigationStart, Router, RoutesRecognized} from './router';
|
||||||
export {RouterOutletMap} from './router_outlet_map';
|
export {RouterOutletMap} from './router_outlet_map';
|
||||||
export {provideRouter} from './router_providers';
|
export {provideRouter} from './router_providers';
|
||||||
export {ExtraOptions} from './common_router_providers';
|
|
||||||
export {ActivatedRoute, ActivatedRouteSnapshot, RouterState, RouterStateSnapshot} from './router_state';
|
export {ActivatedRoute, ActivatedRouteSnapshot, RouterState, RouterStateSnapshot} from './router_state';
|
||||||
export {PRIMARY_OUTLET, Params} from './shared';
|
export {PRIMARY_OUTLET, Params} from './shared';
|
||||||
export {DefaultUrlSerializer, UrlSerializer} from './url_serializer';
|
export {DefaultUrlSerializer, UrlSerializer} from './url_serializer';
|
||||||
|
@ -41,9 +41,7 @@ export interface NavigationExtras {
|
|||||||
export class NavigationStart {
|
export class NavigationStart {
|
||||||
constructor(public id: number, public url: UrlTree) {}
|
constructor(public id: number, public url: UrlTree) {}
|
||||||
|
|
||||||
toString(): string {
|
toString(): string { return `NavigationStart(id: ${this.id}, url: '${this.url}')`; }
|
||||||
return `NavigationStart(id: ${this.id}, url: '${this.url}')`;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -52,9 +50,7 @@ export class NavigationStart {
|
|||||||
export class NavigationEnd {
|
export class NavigationEnd {
|
||||||
constructor(public id: number, public url: UrlTree) {}
|
constructor(public id: number, public url: UrlTree) {}
|
||||||
|
|
||||||
toString(): string {
|
toString(): string { return `NavigationEnd(id: ${this.id}, url: '${this.url}')`; }
|
||||||
return `NavigationEnd(id: ${this.id}, url: '${this.url}')`;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -63,9 +59,7 @@ export class NavigationEnd {
|
|||||||
export class NavigationCancel {
|
export class NavigationCancel {
|
||||||
constructor(public id: number, public url: UrlTree) {}
|
constructor(public id: number, public url: UrlTree) {}
|
||||||
|
|
||||||
toString(): string {
|
toString(): string { return `NavigationCancel(id: ${this.id}, url: '${this.url}')`; }
|
||||||
return `NavigationCancel(id: ${this.id}, url: '${this.url}')`;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -83,7 +77,9 @@ export class NavigationError {
|
|||||||
* An event triggered when routes are recognized
|
* An event triggered when routes are recognized
|
||||||
*/
|
*/
|
||||||
export class RoutesRecognized {
|
export class RoutesRecognized {
|
||||||
constructor(public id: number, public url: UrlTree, public urlAfterRedirects: UrlTree, public state: RouterStateSnapshot) {}
|
constructor(
|
||||||
|
public id: number, public url: UrlTree, public urlAfterRedirects: UrlTree,
|
||||||
|
public state: RouterStateSnapshot) {}
|
||||||
|
|
||||||
toString(): string {
|
toString(): string {
|
||||||
return `RoutesRecognized(id: ${this.id}, url: '${this.url}', urlAfterRedirects: '${this.urlAfterRedirects}', state: ${this.state})`;
|
return `RoutesRecognized(id: ${this.id}, url: '${this.url}', urlAfterRedirects: '${this.urlAfterRedirects}', state: ${this.state})`;
|
||||||
@ -108,7 +104,7 @@ export class Router {
|
|||||||
constructor(
|
constructor(
|
||||||
private rootComponentType: Type, private resolver: ComponentResolver,
|
private rootComponentType: Type, private resolver: ComponentResolver,
|
||||||
private urlSerializer: UrlSerializer, private outletMap: RouterOutletMap,
|
private urlSerializer: UrlSerializer, private outletMap: RouterOutletMap,
|
||||||
private location: Location, private injector:g Injector, private config: RouterConfig) {
|
private location: Location, private injector: g Injector, private config: RouterConfig) {
|
||||||
this.routerEvents = new Subject<Event>();
|
this.routerEvents = new Subject<Event>();
|
||||||
this.currentUrlTree = createEmptyUrlTree();
|
this.currentUrlTree = createEmptyUrlTree();
|
||||||
this.currentRouterState = createEmptyState(this.rootComponentType);
|
this.currentRouterState = createEmptyState(this.rootComponentType);
|
||||||
@ -273,7 +269,8 @@ export class Router {
|
|||||||
})
|
})
|
||||||
|
|
||||||
.mergeMap((newRouterStateSnapshot) => {
|
.mergeMap((newRouterStateSnapshot) => {
|
||||||
this.routerEvents.next(new RoutesRecognized(id, url, updatedUrl, newRouterStateSnapshot));
|
this.routerEvents.next(
|
||||||
|
new RoutesRecognized(id, url, updatedUrl, newRouterStateSnapshot));
|
||||||
return resolve(this.resolver, newRouterStateSnapshot);
|
return resolve(this.resolver, newRouterStateSnapshot);
|
||||||
|
|
||||||
})
|
})
|
||||||
|
@ -25,6 +25,7 @@ import {RouterConfig} from './config';
|
|||||||
*/
|
*/
|
||||||
export function provideRouter(config: RouterConfig, opts: common.ExtraOptions = {}): any[] {
|
export function provideRouter(config: RouterConfig, opts: common.ExtraOptions = {}): any[] {
|
||||||
return [
|
return [
|
||||||
{provide: PlatformLocation, useClass: BrowserPlatformLocation}, ...common.provideRouter(config, opts)
|
{provide: PlatformLocation, useClass: BrowserPlatformLocation},
|
||||||
|
...common.provideRouter(config, opts)
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -34,9 +34,7 @@ export class RouterState extends Tree<ActivatedRoute> {
|
|||||||
super(root);
|
super(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
toString(): string {
|
toString(): string { return this.snapshot.toString(); }
|
||||||
return this.snapshot.toString();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createEmptyState(rootComponent: Type): RouterState {
|
export function createEmptyState(rootComponent: Type): RouterState {
|
||||||
@ -135,7 +133,7 @@ export class ActivatedRouteSnapshot {
|
|||||||
}
|
}
|
||||||
|
|
||||||
toString(): string {
|
toString(): string {
|
||||||
const url = this.urlSegments.map(s => s.toString()).join("/");
|
const url = this.urlSegments.map(s => s.toString()).join('/');
|
||||||
const matched = this._routeConfig ? this._routeConfig.path : '';
|
const matched = this._routeConfig ? this._routeConfig.path : '';
|
||||||
return `Route(url:'${url}', path:'${matched}')`;
|
return `Route(url:'${url}', path:'${matched}')`;
|
||||||
}
|
}
|
||||||
@ -164,9 +162,7 @@ export class RouterStateSnapshot extends Tree<ActivatedRouteSnapshot> {
|
|||||||
super(root);
|
super(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
toString(): string {
|
toString(): string { return serializeNode(this._root); }
|
||||||
return serializeNode(this._root);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function serializeNode(node: TreeNode<ActivatedRouteSnapshot>): string {
|
function serializeNode(node: TreeNode<ActivatedRouteSnapshot>): string {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import {PRIMARY_OUTLET} from './shared';
|
import {PRIMARY_OUTLET} from './shared';
|
||||||
|
import {DefaultUrlSerializer, serializeSegment} from './url_serializer';
|
||||||
import {shallowEqual} from './utils/collection';
|
import {shallowEqual} from './utils/collection';
|
||||||
import {Tree, TreeNode} from './utils/tree';
|
import {Tree, TreeNode} from './utils/tree';
|
||||||
import {DefaultUrlSerializer, serializeSegment} from './url_serializer';
|
|
||||||
|
|
||||||
export function createEmptyUrlTree() {
|
export function createEmptyUrlTree() {
|
||||||
return new UrlTree(
|
return new UrlTree(
|
||||||
@ -21,9 +21,7 @@ export class UrlTree extends Tree<UrlSegment> {
|
|||||||
super(root);
|
super(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
toString(): string {
|
toString(): string { return new DefaultUrlSerializer().serialize(this); }
|
||||||
return new DefaultUrlSerializer().serialize(this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class UrlSegment {
|
export class UrlSegment {
|
||||||
@ -33,9 +31,7 @@ export class UrlSegment {
|
|||||||
constructor(
|
constructor(
|
||||||
public path: string, public parameters: {[key: string]: string}, public outlet: string) {}
|
public path: string, public parameters: {[key: string]: string}, public outlet: string) {}
|
||||||
|
|
||||||
toString(): string {
|
toString(): string { return serializeSegment(this); }
|
||||||
return serializeSegment(this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function equalUrlSegments(a: UrlSegment[], b: UrlSegment[]): boolean {
|
export function equalUrlSegments(a: UrlSegment[], b: UrlSegment[]): boolean {
|
||||||
|
@ -71,7 +71,5 @@ function contains<T>(tree: TreeNode<T>, subtree: TreeNode<T>): boolean {
|
|||||||
export class TreeNode<T> {
|
export class TreeNode<T> {
|
||||||
constructor(public value: T, public children: TreeNode<T>[]) {}
|
constructor(public value: T, public children: TreeNode<T>[]) {}
|
||||||
|
|
||||||
toString(): string {
|
toString(): string { return `TreeNode(${this.value})`; }
|
||||||
return `TreeNode(${this.value})`;
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user