forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathhelpers.ts
53 lines (47 loc) · 1.6 KB
/
helpers.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
* @license
* Copyright Google LLC 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 {convertToParamMap, ParamMap, Params, PRIMARY_OUTLET} from '../src/shared';
import {equalSegments, UrlSegment, UrlSegmentGroup, UrlTree} from '../src/url_tree';
export class Logger {
logs: string[] = [];
add(thing: string) {
this.logs.push(thing);
}
empty() {
this.logs.length = 0;
}
}
export function provideTokenLogger(token: string, returnValue = true as boolean | UrlTree) {
return {
provide: token,
useFactory: (logger: Logger) => () => (logger.add(token), returnValue),
deps: [Logger]
};
}
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 {
return new (ActivatedRouteSnapshot as any)(
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 || {});
}