2017-07-25 14:13:15 -04:00
|
|
|
/**
|
|
|
|
* @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 {Type} from '@angular/core';
|
|
|
|
|
|
|
|
import {Data, ResolveData, Route} from '../src/config';
|
|
|
|
import {ActivatedRouteSnapshot} from '../src/router_state';
|
|
|
|
import {PRIMARY_OUTLET, ParamMap, Params, convertToParamMap} from '../src/shared';
|
|
|
|
import {UrlSegment, UrlSegmentGroup, UrlTree, equalSegments} from '../src/url_tree';
|
|
|
|
|
|
|
|
export class Logger {
|
|
|
|
logs: string[] = [];
|
|
|
|
add(thing: string) { this.logs.push(thing); }
|
|
|
|
empty() { this.logs.length = 0; }
|
|
|
|
}
|
|
|
|
|
2018-10-16 22:50:48 -04:00
|
|
|
export function provideTokenLogger(token: string, returnValue = true as boolean | UrlTree) {
|
2017-07-25 14:13:15 -04:00
|
|
|
return {
|
|
|
|
provide: token,
|
|
|
|
useFactory: (logger: Logger) => () => (logger.add(token), returnValue),
|
|
|
|
deps: [Logger]
|
|
|
|
};
|
2017-09-22 13:51:03 -04:00
|
|
|
}
|
2017-07-25 14:13:15 -04:00
|
|
|
|
|
|
|
export declare type ARSArgs = {
|
|
|
|
url?: UrlSegment[],
|
|
|
|
params?: Params,
|
|
|
|
queryParams?: Params,
|
|
|
|
fragment?: string,
|
|
|
|
data?: Data,
|
|
|
|
outlet?: string,
|
|
|
|
component: Type<any>| string | null,
|
|
|
|
routeConfig?: Route | null,
|
|
|
|
urlSegment?: UrlSegmentGroup,
|
|
|
|
lastPathIndex?: number,
|
|
|
|
resolve?: ResolveData
|
|
|
|
};
|
|
|
|
|
|
|
|
export function createActivatedRouteSnapshot(args: ARSArgs): ActivatedRouteSnapshot {
|
2017-12-17 18:10:54 -05:00
|
|
|
return new (ActivatedRouteSnapshot as any)(
|
2017-07-25 14:13:15 -04:00
|
|
|
args.url || <any>[], args.params || {}, args.queryParams || <any>null,
|
|
|
|
args.fragment || <any>null, args.data || <any>null, args.outlet || <any>null,
|
|
|
|
<any>args.component, args.routeConfig || <any>{}, args.urlSegment || <any>null,
|
|
|
|
args.lastPathIndex || -1, args.resolve || {});
|
|
|
|
}
|