style(lint): re-format modules/@angular
This commit is contained in:
@ -2,4 +2,4 @@
|
||||
* Name of the default outlet outlet.
|
||||
* @type {string}
|
||||
*/
|
||||
export const DEFAULT_OUTLET_NAME = "__DEFAULT";
|
||||
export const DEFAULT_OUTLET_NAME = '__DEFAULT';
|
@ -1,5 +1,5 @@
|
||||
import {RouterOutlet} from "./router_outlet";
|
||||
import {RouterLink} from "./router_link";
|
||||
import {RouterLink} from './router_link';
|
||||
import {RouterOutlet} from './router_outlet';
|
||||
|
||||
/**
|
||||
* A list of directives. To use the router directives like {@link RouterOutlet} and
|
||||
|
@ -1,9 +1,11 @@
|
||||
import {Directive, HostListener, HostBinding, Input, OnDestroy} from '@angular/core';
|
||||
import {LocationStrategy} from '@angular/common';
|
||||
import {Directive, HostBinding, HostListener, Input, OnDestroy} from '@angular/core';
|
||||
|
||||
import {ObservableWrapper} from '../facade/async';
|
||||
import {isArray, isPresent, isString} from '../facade/lang';
|
||||
import {Router} from '../router';
|
||||
import {RouteSegment} from '../segments';
|
||||
import {isString, isArray, isPresent} from '../facade/lang';
|
||||
import {ObservableWrapper} from '../facade/async';
|
||||
import {LocationStrategy} from '@angular/common';
|
||||
|
||||
|
||||
/**
|
||||
* The RouterLink directive lets you link to specific parts of your app.
|
||||
@ -45,8 +47,9 @@ export class RouterLink implements OnDestroy {
|
||||
@HostBinding() href: string;
|
||||
@HostBinding('class.router-link-active') isActive: boolean = false;
|
||||
|
||||
constructor(private _routeSegment: RouteSegment, private _router: Router,
|
||||
private _locationStrategy: LocationStrategy) {
|
||||
constructor(
|
||||
private _routeSegment: RouteSegment, private _router: Router,
|
||||
private _locationStrategy: LocationStrategy) {
|
||||
// because auxiliary links take existing primary and auxiliary routes into account,
|
||||
// we need to update the link whenever params or other routes change.
|
||||
this._subscription =
|
||||
@ -56,7 +59,7 @@ export class RouterLink implements OnDestroy {
|
||||
ngOnDestroy() { ObservableWrapper.dispose(this._subscription); }
|
||||
|
||||
@Input()
|
||||
set routerLink(data: any[] | any) {
|
||||
set routerLink(data: any[]|any) {
|
||||
if (isArray(data)) {
|
||||
this._commands = <any[]>data;
|
||||
} else {
|
||||
@ -66,7 +69,7 @@ export class RouterLink implements OnDestroy {
|
||||
}
|
||||
|
||||
|
||||
@HostListener("click", ["$event.button", "$event.ctrlKey", "$event.metaKey"])
|
||||
@HostListener('click', ['$event.button', '$event.ctrlKey', '$event.metaKey'])
|
||||
onClick(button: number, ctrlKey: boolean, metaKey: boolean): boolean {
|
||||
if (button != 0 || ctrlKey || metaKey) {
|
||||
return true;
|
||||
|
@ -1,15 +1,9 @@
|
||||
import {
|
||||
ResolvedReflectiveProvider,
|
||||
Directive,
|
||||
ViewContainerRef,
|
||||
Attribute,
|
||||
ComponentRef,
|
||||
ComponentFactory,
|
||||
ReflectiveInjector
|
||||
} from '@angular/core';
|
||||
import {RouterOutletMap} from '../router';
|
||||
import {Attribute, ComponentFactory, ComponentRef, Directive, ReflectiveInjector, ResolvedReflectiveProvider, ViewContainerRef} from '@angular/core';
|
||||
|
||||
import {DEFAULT_OUTLET_NAME} from '../constants';
|
||||
import {isPresent, isBlank} from '../facade/lang';
|
||||
import {isBlank, isPresent} from '../facade/lang';
|
||||
import {RouterOutletMap} from '../router';
|
||||
|
||||
|
||||
/**
|
||||
* A router outlet is a placeholder that Angular dynamically fills based on the application's route.
|
||||
@ -31,8 +25,9 @@ export class RouterOutlet {
|
||||
private _activated: ComponentRef<any>;
|
||||
public outletMap: RouterOutletMap;
|
||||
|
||||
constructor(parentOutletMap: RouterOutletMap, private _location: ViewContainerRef,
|
||||
@Attribute('name') name: string) {
|
||||
constructor(
|
||||
parentOutletMap: RouterOutletMap, private _location: ViewContainerRef,
|
||||
@Attribute('name') name: string) {
|
||||
parentOutletMap.registerOutlet(isBlank(name) ? DEFAULT_OUTLET_NAME : name, this);
|
||||
}
|
||||
|
||||
@ -54,8 +49,9 @@ export class RouterOutlet {
|
||||
/**
|
||||
* Called by the Router to instantiate a new component.
|
||||
*/
|
||||
activate(factory: ComponentFactory<any>, providers: ResolvedReflectiveProvider[],
|
||||
outletMap: RouterOutletMap): ComponentRef<any> {
|
||||
activate(
|
||||
factory: ComponentFactory<any>, providers: ResolvedReflectiveProvider[],
|
||||
outletMap: RouterOutletMap): ComponentRef<any> {
|
||||
this.outletMap = outletMap;
|
||||
let inj = ReflectiveInjector.fromResolvedProviders(providers, this._location.parentInjector);
|
||||
this._activated = this._location.createComponent(factory, this._location.length, inj, []);
|
||||
|
@ -1,4 +1,5 @@
|
||||
import {RouteSegment, Tree, RouteTree} from './segments';
|
||||
import {RouteSegment, RouteTree, Tree} from './segments';
|
||||
|
||||
|
||||
/**
|
||||
* Defines route lifecycle method `routerOnActivate`, which is called by the router at the end of a
|
||||
@ -8,8 +9,8 @@ import {RouteSegment, Tree, RouteTree} from './segments';
|
||||
* component and with the corresponding route trees.
|
||||
*/
|
||||
export interface OnActivate {
|
||||
routerOnActivate(curr: RouteSegment, prev?: RouteSegment, currTree?: RouteTree,
|
||||
prevTree?: RouteTree): void;
|
||||
routerOnActivate(
|
||||
curr: RouteSegment, prev?: RouteSegment, currTree?: RouteTree, prevTree?: RouteTree): void;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4,5 +4,5 @@ export function hasLifecycleHook(name: string, obj: Object): boolean {
|
||||
if (isBlank(obj)) return false;
|
||||
let type = obj.constructor;
|
||||
if (!(type instanceof Type)) return false;
|
||||
return name in(<any>type).prototype;
|
||||
return name in (<any>type).prototype;
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
import {Tree, TreeNode, UrlSegment, RouteSegment, rootNode, UrlTree, RouteTree} from './segments';
|
||||
import {isBlank, isPresent, isString, isStringMap} from './facade/lang';
|
||||
import {BaseException} from './facade/exceptions';
|
||||
import {ListWrapper, StringMapWrapper} from './facade/collection';
|
||||
import {BaseException} from './facade/exceptions';
|
||||
import {isBlank, isPresent, isString, isStringMap} from './facade/lang';
|
||||
import {RouteSegment, RouteTree, Tree, TreeNode, UrlSegment, UrlTree, rootNode} from './segments';
|
||||
|
||||
export function link(segment: RouteSegment, routeTree: RouteTree, urlTree: UrlTree,
|
||||
commands: any[]): UrlTree {
|
||||
export function link(
|
||||
segment: RouteSegment, routeTree: RouteTree, urlTree: UrlTree, commands: any[]): UrlTree {
|
||||
if (commands.length === 0) return urlTree;
|
||||
|
||||
let normalizedCommands = _normalizeCommands(commands);
|
||||
@ -13,10 +13,9 @@ export function link(segment: RouteSegment, routeTree: RouteTree, urlTree: UrlTr
|
||||
}
|
||||
|
||||
let startingNode = _findStartingNode(normalizedCommands, urlTree, segment, routeTree);
|
||||
let updated =
|
||||
normalizedCommands.commands.length > 0 ?
|
||||
_updateMany(ListWrapper.clone(startingNode.children), normalizedCommands.commands) :
|
||||
[];
|
||||
let updated = normalizedCommands.commands.length > 0 ?
|
||||
_updateMany(ListWrapper.clone(startingNode.children), normalizedCommands.commands) :
|
||||
[];
|
||||
let newRoot = _constructNewTree(rootNode(urlTree), startingNode, updated);
|
||||
|
||||
return new UrlTree(newRoot);
|
||||
@ -24,16 +23,16 @@ export function link(segment: RouteSegment, routeTree: RouteTree, urlTree: UrlTr
|
||||
|
||||
function _navigateToRoot(normalizedChange: _NormalizedNavigationCommands): boolean {
|
||||
return normalizedChange.isAbsolute && normalizedChange.commands.length === 1 &&
|
||||
normalizedChange.commands[0] == "/";
|
||||
normalizedChange.commands[0] == '/';
|
||||
}
|
||||
|
||||
class _NormalizedNavigationCommands {
|
||||
constructor(public isAbsolute: boolean, public numberOfDoubleDots: number,
|
||||
public commands: any[]) {}
|
||||
constructor(
|
||||
public isAbsolute: boolean, public numberOfDoubleDots: number, public commands: any[]) {}
|
||||
}
|
||||
|
||||
function _normalizeCommands(commands: any[]): _NormalizedNavigationCommands {
|
||||
if (isString(commands[0]) && commands.length === 1 && commands[0] == "/") {
|
||||
if (isString(commands[0]) && commands.length === 1 && commands[0] == '/') {
|
||||
return new _NormalizedNavigationCommands(true, 0, commands);
|
||||
}
|
||||
|
||||
@ -55,11 +54,11 @@ function _normalizeCommands(commands: any[]): _NormalizedNavigationCommands {
|
||||
|
||||
// first exp is treated in a special way
|
||||
if (i == 0) {
|
||||
if (j == 0 && cc == ".") { // './a'
|
||||
if (j == 0 && cc == '.') { // './a'
|
||||
// skip it
|
||||
} else if (j == 0 && cc == "") { // '/a'
|
||||
} else if (j == 0 && cc == '') { // '/a'
|
||||
isAbsolute = true;
|
||||
} else if (cc == "..") { // '../a'
|
||||
} else if (cc == '..') { // '../a'
|
||||
numberOfDoubleDots++;
|
||||
} else if (cc != '') {
|
||||
res.push(cc);
|
||||
@ -76,8 +75,9 @@ function _normalizeCommands(commands: any[]): _NormalizedNavigationCommands {
|
||||
return new _NormalizedNavigationCommands(isAbsolute, numberOfDoubleDots, res);
|
||||
}
|
||||
|
||||
function _findUrlSegment(segment: RouteSegment, routeTree: RouteTree, urlTree: UrlTree,
|
||||
numberOfDoubleDots: number): UrlSegment {
|
||||
function _findUrlSegment(
|
||||
segment: RouteSegment, routeTree: RouteTree, urlTree: UrlTree,
|
||||
numberOfDoubleDots: number): UrlSegment {
|
||||
let s = segment;
|
||||
while (s.urlSegments.length === 0) {
|
||||
s = routeTree.parent(s);
|
||||
@ -85,13 +85,14 @@ function _findUrlSegment(segment: RouteSegment, routeTree: RouteTree, urlTree: U
|
||||
let urlSegment = ListWrapper.last(s.urlSegments);
|
||||
let path = urlTree.pathFromRoot(urlSegment);
|
||||
if (path.length <= numberOfDoubleDots) {
|
||||
throw new BaseException("Invalid number of '../'");
|
||||
throw new BaseException('Invalid number of \'../\'');
|
||||
}
|
||||
return path[path.length - 1 - numberOfDoubleDots];
|
||||
}
|
||||
|
||||
function _findStartingNode(normalizedChange: _NormalizedNavigationCommands, urlTree: UrlTree,
|
||||
segment: RouteSegment, routeTree: RouteTree): TreeNode<UrlSegment> {
|
||||
function _findStartingNode(
|
||||
normalizedChange: _NormalizedNavigationCommands, urlTree: UrlTree, segment: RouteSegment,
|
||||
routeTree: RouteTree): TreeNode<UrlSegment> {
|
||||
if (normalizedChange.isAbsolute) {
|
||||
return rootNode(urlTree);
|
||||
} else {
|
||||
@ -110,8 +111,9 @@ function _findMatchingNode(segment: UrlSegment, node: TreeNode<UrlSegment>): Tre
|
||||
return null;
|
||||
}
|
||||
|
||||
function _constructNewTree(node: TreeNode<UrlSegment>, original: TreeNode<UrlSegment>,
|
||||
updated: TreeNode<UrlSegment>[]): TreeNode<UrlSegment> {
|
||||
function _constructNewTree(
|
||||
node: TreeNode<UrlSegment>, original: TreeNode<UrlSegment>,
|
||||
updated: TreeNode<UrlSegment>[]): TreeNode<UrlSegment> {
|
||||
if (node === original) {
|
||||
return new TreeNode<UrlSegment>(node.value, updated);
|
||||
} else {
|
||||
@ -167,7 +169,9 @@ function _update(node: TreeNode<UrlSegment>, commands: any[]): TreeNode<UrlSegme
|
||||
|
||||
function _stringify(params: {[key: string]: any}): {[key: string]: string} {
|
||||
let res = {};
|
||||
StringMapWrapper.forEach(params, (v: any /** TODO #9100 */, k: any /** TODO #9100 */) => (res as any /** TODO #9100 */)[k] = v.toString());
|
||||
StringMapWrapper.forEach(
|
||||
params, (v: any /** TODO #9100 */, k: any /** TODO #9100 */) =>
|
||||
(res as any /** TODO #9100 */)[k] = v.toString());
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -175,8 +179,8 @@ function _compare(path: string, params: {[key: string]: any}, segment: UrlSegmen
|
||||
return path == segment.segment && StringMapWrapper.equals(params, segment.parameters);
|
||||
}
|
||||
|
||||
function _recurse(urlSegment: UrlSegment, node: TreeNode<UrlSegment>,
|
||||
rest: any[]): TreeNode<UrlSegment> {
|
||||
function _recurse(
|
||||
urlSegment: UrlSegment, node: TreeNode<UrlSegment>, rest: any[]): TreeNode<UrlSegment> {
|
||||
if (rest.length === 0) {
|
||||
return new TreeNode<UrlSegment>(urlSegment, []);
|
||||
}
|
||||
@ -198,12 +202,12 @@ function _updateMany(nodes: TreeNode<UrlSegment>[], commands: any[]): TreeNode<U
|
||||
|
||||
function _segment(commands: any[]): any {
|
||||
if (!isString(commands[0])) return commands[0];
|
||||
let parts = commands[0].toString().split(":");
|
||||
let parts = commands[0].toString().split(':');
|
||||
return parts.length > 1 ? parts[1] : commands[0];
|
||||
}
|
||||
|
||||
function _outlet(commands: any[]): string {
|
||||
if (!isString(commands[0])) return null;
|
||||
let parts = commands[0].toString().split(":");
|
||||
let parts = commands[0].toString().split(':');
|
||||
return parts.length > 1 ? parts[0] : null;
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
import {RoutesMetadata, RouteMetadata} from "./metadata";
|
||||
import {makeDecorator} from '../core_private';
|
||||
|
||||
import {RouteMetadata, RoutesMetadata} from './metadata';
|
||||
|
||||
|
||||
/**
|
||||
* Defines routes for a given component.
|
||||
*
|
||||
|
@ -1,5 +1,5 @@
|
||||
import {Type} from '@angular/core';
|
||||
import {stringify} from "../facade/lang";
|
||||
import {stringify} from '../facade/lang';
|
||||
|
||||
/**
|
||||
* Information about a route.
|
||||
@ -22,7 +22,7 @@ import {stringify} from "../facade/lang";
|
||||
*/
|
||||
export abstract class RouteMetadata {
|
||||
abstract get path(): string;
|
||||
abstract get component(): Type | string;
|
||||
abstract get component(): Type|string;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -31,8 +31,8 @@ export abstract class RouteMetadata {
|
||||
*/
|
||||
export class Route implements RouteMetadata {
|
||||
path: string;
|
||||
component: Type | string;
|
||||
constructor({path, component}: {path?: string, component?: Type | string} = {}) {
|
||||
component: Type|string;
|
||||
constructor({path, component}: {path?: string, component?: Type|string} = {}) {
|
||||
this.path = path;
|
||||
this.component = component;
|
||||
}
|
||||
|
@ -1,31 +1,24 @@
|
||||
import {
|
||||
RouteSegment,
|
||||
UrlSegment,
|
||||
Tree,
|
||||
TreeNode,
|
||||
rootNode,
|
||||
UrlTree,
|
||||
RouteTree,
|
||||
equalUrlSegments
|
||||
} from './segments';
|
||||
import {RoutesMetadata, RouteMetadata} from './metadata/metadata';
|
||||
import {Type, isBlank, isPresent, stringify} from './facade/lang';
|
||||
import {ListWrapper, StringMapWrapper} from './facade/collection';
|
||||
import {PromiseWrapper} from './facade/promise';
|
||||
import {BaseException, ComponentFactory, ComponentResolver} from '@angular/core';
|
||||
|
||||
import {DEFAULT_OUTLET_NAME} from './constants';
|
||||
import {reflector} from './core_private';
|
||||
import {ListWrapper, StringMapWrapper} from './facade/collection';
|
||||
import {Type, isBlank, isPresent, stringify} from './facade/lang';
|
||||
import {PromiseWrapper} from './facade/promise';
|
||||
import {RouteMetadata, RoutesMetadata} from './metadata/metadata';
|
||||
import {RouteSegment, RouteTree, Tree, TreeNode, UrlSegment, UrlTree, equalUrlSegments, rootNode} from './segments';
|
||||
|
||||
export function recognize(componentResolver: ComponentResolver, rootComponent: Type, url: UrlTree,
|
||||
existingTree: RouteTree): Promise<RouteTree> {
|
||||
export function recognize(
|
||||
componentResolver: ComponentResolver, rootComponent: Type, url: UrlTree,
|
||||
existingTree: RouteTree): Promise<RouteTree> {
|
||||
let matched = new _MatchResult(rootComponent, [url.root], {}, rootNode(url).children, []);
|
||||
return _constructSegment(componentResolver, matched, rootNode(existingTree))
|
||||
.then(roots => new RouteTree(roots[0]));
|
||||
}
|
||||
|
||||
function _recognize(componentResolver: ComponentResolver, parentComponent: Type,
|
||||
url: TreeNode<UrlSegment>,
|
||||
existingSegments: TreeNode<RouteSegment>[]): Promise<TreeNode<RouteSegment>[]> {
|
||||
function _recognize(
|
||||
componentResolver: ComponentResolver, parentComponent: Type, url: TreeNode<UrlSegment>,
|
||||
existingSegments: TreeNode<RouteSegment>[]): Promise<TreeNode<RouteSegment>[]> {
|
||||
let metadata = _readMetadata(parentComponent); // should read from the factory instead
|
||||
if (isBlank(metadata)) {
|
||||
throw new BaseException(
|
||||
@ -60,24 +53,24 @@ function _recognizeMany(
|
||||
function _constructSegment(
|
||||
componentResolver: ComponentResolver, matched: _MatchResult,
|
||||
existingSegment: TreeNode<RouteSegment>): Promise<TreeNode<RouteSegment>[]> {
|
||||
return componentResolver.resolveComponent(matched.component)
|
||||
.then(factory => {
|
||||
let segment = _createOrReuseSegment(matched, factory, existingSegment);
|
||||
let existingChildren = isPresent(existingSegment) ? existingSegment.children : [];
|
||||
return componentResolver.resolveComponent(matched.component).then(factory => {
|
||||
let segment = _createOrReuseSegment(matched, factory, existingSegment);
|
||||
let existingChildren = isPresent(existingSegment) ? existingSegment.children : [];
|
||||
|
||||
if (matched.leftOverUrl.length > 0) {
|
||||
return _recognizeMany(componentResolver, factory.componentType, matched.leftOverUrl,
|
||||
existingChildren)
|
||||
.then(children => [new TreeNode<RouteSegment>(segment, children)]);
|
||||
} else {
|
||||
return _recognizeLeftOvers(componentResolver, factory.componentType, existingChildren)
|
||||
.then(children => [new TreeNode<RouteSegment>(segment, children)]);
|
||||
}
|
||||
});
|
||||
if (matched.leftOverUrl.length > 0) {
|
||||
return _recognizeMany(
|
||||
componentResolver, factory.componentType, matched.leftOverUrl, existingChildren)
|
||||
.then(children => [new TreeNode<RouteSegment>(segment, children)]);
|
||||
} else {
|
||||
return _recognizeLeftOvers(componentResolver, factory.componentType, existingChildren)
|
||||
.then(children => [new TreeNode<RouteSegment>(segment, children)]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function _createOrReuseSegment(matched: _MatchResult, factory: ComponentFactory<any>,
|
||||
segmentNode: TreeNode<RouteSegment>): RouteSegment {
|
||||
function _createOrReuseSegment(
|
||||
matched: _MatchResult, factory: ComponentFactory<any>,
|
||||
segmentNode: TreeNode<RouteSegment>): RouteSegment {
|
||||
let segment = isPresent(segmentNode) ? segmentNode.value : null;
|
||||
|
||||
if (isPresent(segment) && equalUrlSegments(segment.urlSegments, matched.consumedUrlSegments) &&
|
||||
@ -85,44 +78,43 @@ function _createOrReuseSegment(matched: _MatchResult, factory: ComponentFactory<
|
||||
segment.outlet == matched.outlet && factory.componentType == segment.type) {
|
||||
return segment;
|
||||
} else {
|
||||
return new RouteSegment(matched.consumedUrlSegments, matched.parameters, matched.outlet,
|
||||
factory.componentType, factory);
|
||||
return new RouteSegment(
|
||||
matched.consumedUrlSegments, matched.parameters, matched.outlet, factory.componentType,
|
||||
factory);
|
||||
}
|
||||
}
|
||||
|
||||
function _recognizeLeftOvers(
|
||||
componentResolver: ComponentResolver, parentComponent: Type,
|
||||
existingSegments: TreeNode<RouteSegment>[]): Promise<TreeNode<RouteSegment>[]> {
|
||||
return componentResolver.resolveComponent(parentComponent)
|
||||
.then(factory => {
|
||||
let metadata = _readMetadata(factory.componentType);
|
||||
if (isBlank(metadata)) {
|
||||
return [];
|
||||
}
|
||||
return componentResolver.resolveComponent(parentComponent).then(factory => {
|
||||
let metadata = _readMetadata(factory.componentType);
|
||||
if (isBlank(metadata)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
let r = (<any[]>metadata.routes).filter(r => r.path == "" || r.path == "/");
|
||||
if (r.length === 0) {
|
||||
return PromiseWrapper.resolve([]);
|
||||
} else {
|
||||
let segmentsWithMatchingOutlet =
|
||||
existingSegments.filter(r => r.value.outlet == DEFAULT_OUTLET_NAME);
|
||||
let segmentWithMatchingOutlet =
|
||||
segmentsWithMatchingOutlet.length > 0 ? segmentsWithMatchingOutlet[0] : null;
|
||||
let existingChildren =
|
||||
isPresent(segmentWithMatchingOutlet) ? segmentWithMatchingOutlet.children : [];
|
||||
let r = (<any[]>metadata.routes).filter(r => r.path == '' || r.path == '/');
|
||||
if (r.length === 0) {
|
||||
return PromiseWrapper.resolve([]);
|
||||
} else {
|
||||
let segmentsWithMatchingOutlet =
|
||||
existingSegments.filter(r => r.value.outlet == DEFAULT_OUTLET_NAME);
|
||||
let segmentWithMatchingOutlet =
|
||||
segmentsWithMatchingOutlet.length > 0 ? segmentsWithMatchingOutlet[0] : null;
|
||||
let existingChildren =
|
||||
isPresent(segmentWithMatchingOutlet) ? segmentWithMatchingOutlet.children : [];
|
||||
|
||||
return _recognizeLeftOvers(componentResolver, r[0].component, existingChildren)
|
||||
.then(children => {
|
||||
return componentResolver.resolveComponent(r[0].component)
|
||||
.then(factory => {
|
||||
let segment =
|
||||
_createOrReuseSegment(new _MatchResult(r[0].component, [], {}, [], []),
|
||||
factory, segmentWithMatchingOutlet);
|
||||
return [new TreeNode<RouteSegment>(segment, children)];
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
return _recognizeLeftOvers(componentResolver, r[0].component, existingChildren)
|
||||
.then(children => {
|
||||
return componentResolver.resolveComponent(r[0].component).then(factory => {
|
||||
let segment = _createOrReuseSegment(
|
||||
new _MatchResult(r[0].component, [], {}, [], []), factory,
|
||||
segmentWithMatchingOutlet);
|
||||
return [new TreeNode<RouteSegment>(segment, children)];
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function _match(metadata: RoutesMetadata, url: TreeNode<UrlSegment>): _MatchResult {
|
||||
@ -132,19 +124,19 @@ function _match(metadata: RoutesMetadata, url: TreeNode<UrlSegment>): _MatchResu
|
||||
return matchingResult;
|
||||
}
|
||||
}
|
||||
let availableRoutes = metadata.routes.map(r => `'${r.path}'`).join(", ");
|
||||
let availableRoutes = metadata.routes.map(r => `'${r.path}'`).join(', ');
|
||||
throw new BaseException(
|
||||
`Cannot match any routes. Current segment: '${url.value}'. Available routes: [${availableRoutes}].`);
|
||||
}
|
||||
|
||||
function _matchWithParts(route: RouteMetadata, url: TreeNode<UrlSegment>): _MatchResult {
|
||||
let path = route.path.startsWith("/") ? route.path.substring(1) : route.path;
|
||||
let path = route.path.startsWith('/') ? route.path.substring(1) : route.path;
|
||||
|
||||
if (path == "*") {
|
||||
if (path == '*') {
|
||||
return new _MatchResult(route.component, [], null, [], []);
|
||||
}
|
||||
|
||||
let parts = path.split("/");
|
||||
let parts = path.split('/');
|
||||
let positionalParams = {};
|
||||
let consumedUrlSegments: any[] /** TODO #9100 */ = [];
|
||||
|
||||
@ -158,7 +150,7 @@ function _matchWithParts(route: RouteMetadata, url: TreeNode<UrlSegment>): _Matc
|
||||
let p = parts[i];
|
||||
let isLastSegment = i === parts.length - 1;
|
||||
let isLastParent = i === parts.length - 2;
|
||||
let isPosParam = p.startsWith(":");
|
||||
let isPosParam = p.startsWith(':');
|
||||
|
||||
if (!isPosParam && p != current.value.segment) return null;
|
||||
if (isLastSegment) {
|
||||
@ -181,8 +173,8 @@ function _matchWithParts(route: RouteMetadata, url: TreeNode<UrlSegment>): _Matc
|
||||
let parameters = <{[key: string]: string}>StringMapWrapper.merge(p, positionalParams);
|
||||
let axuUrlSubtrees = isPresent(lastParent) ? lastParent.children.slice(1) : [];
|
||||
|
||||
return new _MatchResult(route.component, consumedUrlSegments, parameters, lastSegment.children,
|
||||
axuUrlSubtrees);
|
||||
return new _MatchResult(
|
||||
route.component, consumedUrlSegments, parameters, lastSegment.children, axuUrlSubtrees);
|
||||
}
|
||||
|
||||
function _checkOutletNameUniqueness(nodes: TreeNode<RouteSegment>[]): TreeNode<RouteSegment>[] {
|
||||
@ -200,14 +192,15 @@ function _checkOutletNameUniqueness(nodes: TreeNode<RouteSegment>[]): TreeNode<R
|
||||
}
|
||||
|
||||
class _MatchResult {
|
||||
constructor(public component: Type | string, public consumedUrlSegments: UrlSegment[],
|
||||
public parameters: {[key: string]: string},
|
||||
public leftOverUrl: TreeNode<UrlSegment>[], public aux: TreeNode<UrlSegment>[]) {}
|
||||
constructor(
|
||||
public component: Type|string, public consumedUrlSegments: UrlSegment[],
|
||||
public parameters: {[key: string]: string}, public leftOverUrl: TreeNode<UrlSegment>[],
|
||||
public aux: TreeNode<UrlSegment>[]) {}
|
||||
|
||||
get outlet(): string {
|
||||
return this.consumedUrlSegments.length === 0 || isBlank(this.consumedUrlSegments[0].outlet) ?
|
||||
DEFAULT_OUTLET_NAME :
|
||||
this.consumedUrlSegments[0].outlet;
|
||||
DEFAULT_OUTLET_NAME :
|
||||
this.consumedUrlSegments[0].outlet;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,27 +1,17 @@
|
||||
import {BaseException, provide, ReflectiveInjector, ComponentResolver} from '@angular/core';
|
||||
import {RouterOutlet} from './directives/router_outlet';
|
||||
import {Type, isBlank, isPresent} from './facade/lang';
|
||||
import {ListWrapper, StringMapWrapper} from './facade/collection';
|
||||
import {EventEmitter, Observable, PromiseWrapper, ObservableWrapper} from './facade/async';
|
||||
import {RouterUrlSerializer} from './router_url_serializer';
|
||||
import {CanDeactivate} from './interfaces';
|
||||
import {recognize} from './recognize';
|
||||
import {Location} from '@angular/common';
|
||||
import {link} from './link';
|
||||
import {BaseException, ComponentResolver, ReflectiveInjector, provide} from '@angular/core';
|
||||
|
||||
import {
|
||||
routeSegmentComponentFactory,
|
||||
RouteSegment,
|
||||
UrlTree,
|
||||
RouteTree,
|
||||
rootNode,
|
||||
TreeNode,
|
||||
UrlSegment,
|
||||
serializeRouteSegmentTree,
|
||||
createEmptyRouteTree
|
||||
} from './segments';
|
||||
import {hasLifecycleHook} from './lifecycle_reflector';
|
||||
import {DEFAULT_OUTLET_NAME} from './constants';
|
||||
import {RouterOutlet} from './directives/router_outlet';
|
||||
import {EventEmitter, Observable, ObservableWrapper, PromiseWrapper} from './facade/async';
|
||||
import {ListWrapper, StringMapWrapper} from './facade/collection';
|
||||
import {Type, isBlank, isPresent} from './facade/lang';
|
||||
import {CanDeactivate} from './interfaces';
|
||||
import {hasLifecycleHook} from './lifecycle_reflector';
|
||||
import {link} from './link';
|
||||
import {recognize} from './recognize';
|
||||
import {RouterUrlSerializer} from './router_url_serializer';
|
||||
import {RouteSegment, RouteTree, TreeNode, UrlSegment, UrlTree, createEmptyRouteTree, rootNode, routeSegmentComponentFactory, serializeRouteSegmentTree} from './segments';
|
||||
|
||||
export class RouterOutletMap {
|
||||
/** @internal */
|
||||
@ -44,10 +34,10 @@ export class Router {
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
constructor(private _rootComponent: Object, private _rootComponentType: Type,
|
||||
private _componentResolver: ComponentResolver,
|
||||
private _urlSerializer: RouterUrlSerializer,
|
||||
private _routerOutletMap: RouterOutletMap, private _location: Location) {
|
||||
constructor(
|
||||
private _rootComponent: Object, private _rootComponentType: Type,
|
||||
private _componentResolver: ComponentResolver, private _urlSerializer: RouterUrlSerializer,
|
||||
private _routerOutletMap: RouterOutletMap, private _location: Location) {
|
||||
this._routeTree = createEmptyRouteTree(this._rootComponentType);
|
||||
this._setUpLocationChangeListener();
|
||||
this.navigateByUrl(this._location.path());
|
||||
@ -149,24 +139,24 @@ export class Router {
|
||||
private _navigate(url: UrlTree, preventPushState?: boolean): Promise<void> {
|
||||
this._urlTree = url;
|
||||
return recognize(this._componentResolver, this._rootComponentType, url, this._routeTree)
|
||||
.then(currTree => {
|
||||
return new _ActivateSegments(currTree, this._routeTree)
|
||||
.activate(this._routerOutletMap, this._rootComponent)
|
||||
.then(updated => {
|
||||
if (updated) {
|
||||
this._routeTree = currTree;
|
||||
if (isBlank(preventPushState) || !preventPushState) {
|
||||
let path = this._urlSerializer.serialize(this._urlTree);
|
||||
if (this._location.isCurrentPathEqualTo(path)) {
|
||||
this._location.replaceState(path);
|
||||
} else {
|
||||
this._location.go(path);
|
||||
.then(currTree => {
|
||||
return new _ActivateSegments(currTree, this._routeTree)
|
||||
.activate(this._routerOutletMap, this._rootComponent)
|
||||
.then(updated => {
|
||||
if (updated) {
|
||||
this._routeTree = currTree;
|
||||
if (isBlank(preventPushState) || !preventPushState) {
|
||||
let path = this._urlSerializer.serialize(this._urlTree);
|
||||
if (this._location.isCurrentPathEqualTo(path)) {
|
||||
this._location.replaceState(path);
|
||||
} else {
|
||||
this._location.go(path);
|
||||
}
|
||||
}
|
||||
this._changes.emit(null);
|
||||
}
|
||||
}
|
||||
this._changes.emit(null);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -181,18 +171,18 @@ class _ActivateSegments {
|
||||
let prevRoot = isPresent(this.prevTree) ? rootNode(this.prevTree) : null;
|
||||
let currRoot = rootNode(this.currTree);
|
||||
|
||||
return this.canDeactivate(currRoot, prevRoot, parentOutletMap, rootComponent)
|
||||
.then(res => {
|
||||
this.performMutation = true;
|
||||
if (res) {
|
||||
this.activateChildSegments(currRoot, prevRoot, parentOutletMap, [rootComponent]);
|
||||
}
|
||||
return res;
|
||||
});
|
||||
return this.canDeactivate(currRoot, prevRoot, parentOutletMap, rootComponent).then(res => {
|
||||
this.performMutation = true;
|
||||
if (res) {
|
||||
this.activateChildSegments(currRoot, prevRoot, parentOutletMap, [rootComponent]);
|
||||
}
|
||||
return res;
|
||||
});
|
||||
}
|
||||
|
||||
private canDeactivate(currRoot: TreeNode<RouteSegment>, prevRoot: TreeNode<RouteSegment>,
|
||||
outletMap: RouterOutletMap, rootComponent: Object): Promise<boolean> {
|
||||
private canDeactivate(
|
||||
currRoot: TreeNode<RouteSegment>, prevRoot: TreeNode<RouteSegment>,
|
||||
outletMap: RouterOutletMap, rootComponent: Object): Promise<boolean> {
|
||||
this.performMutation = false;
|
||||
this.activateChildSegments(currRoot, prevRoot, outletMap, [rootComponent]);
|
||||
|
||||
@ -204,7 +194,7 @@ class _ActivateSegments {
|
||||
let curr = PromiseWrapper.resolve(true);
|
||||
for (let p of ListWrapper.reversed(path)) {
|
||||
curr = curr.then(_ => {
|
||||
if (hasLifecycleHook("routerCanDeactivate", p)) {
|
||||
if (hasLifecycleHook('routerCanDeactivate', p)) {
|
||||
return (<CanDeactivate>p).routerCanDeactivate(this.prevTree, this.currTree);
|
||||
} else {
|
||||
return _;
|
||||
@ -214,35 +204,35 @@ class _ActivateSegments {
|
||||
return curr;
|
||||
}
|
||||
|
||||
private activateChildSegments(currNode: TreeNode<RouteSegment>, prevNode: TreeNode<RouteSegment>,
|
||||
outletMap: RouterOutletMap, components: Object[]): void {
|
||||
let prevChildren = isPresent(prevNode) ?
|
||||
prevNode.children.reduce(
|
||||
(m, c) => {
|
||||
(m as any /** TODO #9100 */)[c.value.outlet] = c;
|
||||
return m;
|
||||
},
|
||||
{}) :
|
||||
{};
|
||||
private activateChildSegments(
|
||||
currNode: TreeNode<RouteSegment>, prevNode: TreeNode<RouteSegment>,
|
||||
outletMap: RouterOutletMap, components: Object[]): void {
|
||||
let prevChildren = isPresent(prevNode) ? prevNode.children.reduce((m, c) => {
|
||||
(m as any /** TODO #9100 */)[c.value.outlet] = c;
|
||||
return m;
|
||||
}, {}) : {};
|
||||
|
||||
currNode.children.forEach(c => {
|
||||
this.activateSegments(c, (prevChildren as any /** TODO #9100 */)[c.value.outlet], outletMap, components);
|
||||
this.activateSegments(
|
||||
c, (prevChildren as any /** TODO #9100 */)[c.value.outlet], outletMap, components);
|
||||
StringMapWrapper.delete(prevChildren, c.value.outlet);
|
||||
});
|
||||
|
||||
StringMapWrapper.forEach(prevChildren,
|
||||
(v: any /** TODO #9100 */, k: any /** TODO #9100 */) => this.deactivateOutlet(outletMap._outlets[k], components));
|
||||
StringMapWrapper.forEach(
|
||||
prevChildren, (v: any /** TODO #9100 */, k: any /** TODO #9100 */) =>
|
||||
this.deactivateOutlet(outletMap._outlets[k], components));
|
||||
}
|
||||
|
||||
activateSegments(currNode: TreeNode<RouteSegment>, prevNode: TreeNode<RouteSegment>,
|
||||
parentOutletMap: RouterOutletMap, components: Object[]): void {
|
||||
activateSegments(
|
||||
currNode: TreeNode<RouteSegment>, prevNode: TreeNode<RouteSegment>,
|
||||
parentOutletMap: RouterOutletMap, components: Object[]): void {
|
||||
let curr = currNode.value;
|
||||
let prev = isPresent(prevNode) ? prevNode.value : null;
|
||||
let outlet = this.getOutlet(parentOutletMap, currNode.value);
|
||||
|
||||
if (curr === prev) {
|
||||
this.activateChildSegments(currNode, prevNode, outlet.outletMap,
|
||||
components.concat([outlet.component]));
|
||||
this.activateChildSegments(
|
||||
currNode, prevNode, outlet.outletMap, components.concat([outlet.component]));
|
||||
} else {
|
||||
this.deactivateOutlet(outlet, components);
|
||||
if (this.performMutation) {
|
||||
@ -253,12 +243,13 @@ class _ActivateSegments {
|
||||
}
|
||||
}
|
||||
|
||||
private activateNewSegments(outletMap: RouterOutletMap, curr: RouteSegment, prev: RouteSegment,
|
||||
outlet: RouterOutlet): Object {
|
||||
private activateNewSegments(
|
||||
outletMap: RouterOutletMap, curr: RouteSegment, prev: RouteSegment,
|
||||
outlet: RouterOutlet): Object {
|
||||
let resolved = ReflectiveInjector.resolve(
|
||||
[{provide: RouterOutletMap, useValue: outletMap}, {provide: RouteSegment, useValue: curr}]);
|
||||
let ref = outlet.activate(routeSegmentComponentFactory(curr), resolved, outletMap);
|
||||
if (hasLifecycleHook("routerOnActivate", ref.instance)) {
|
||||
if (hasLifecycleHook('routerOnActivate', ref.instance)) {
|
||||
ref.instance.routerOnActivate(curr, prev, this.currTree, this.prevTree);
|
||||
}
|
||||
return ref.instance;
|
||||
@ -278,8 +269,9 @@ class _ActivateSegments {
|
||||
|
||||
private deactivateOutlet(outlet: RouterOutlet, components: Object[]): void {
|
||||
if (isPresent(outlet) && outlet.isActivated) {
|
||||
StringMapWrapper.forEach(outlet.outletMap._outlets,
|
||||
(v: any /** TODO #9100 */, k: any /** TODO #9100 */) => this.deactivateOutlet(v, components));
|
||||
StringMapWrapper.forEach(
|
||||
outlet.outletMap._outlets, (v: any /** TODO #9100 */, k: any /** TODO #9100 */) =>
|
||||
this.deactivateOutlet(v, components));
|
||||
if (this.performMutation) {
|
||||
outlet.deactivate();
|
||||
} else {
|
||||
|
@ -1,8 +1,10 @@
|
||||
import {Location, LocationStrategy, PathLocationStrategy} from '@angular/common';
|
||||
import {ApplicationRef, BaseException, ComponentResolver} from '@angular/core';
|
||||
import {LocationStrategy, PathLocationStrategy, Location} from '@angular/common';
|
||||
|
||||
import {Router, RouterOutletMap} from './router';
|
||||
import {DefaultRouterUrlSerializer, RouterUrlSerializer} from './router_url_serializer';
|
||||
import {RouteSegment} from './segments';
|
||||
import {RouterUrlSerializer, DefaultRouterUrlSerializer} from './router_url_serializer';
|
||||
|
||||
|
||||
/**
|
||||
* The Platform agnostic ROUTER PROVIDERS
|
||||
@ -15,20 +17,20 @@ export const ROUTER_PROVIDERS_COMMON: any[] = /*@ts2dart_const*/[
|
||||
provide: Router,
|
||||
useFactory: routerFactory,
|
||||
deps: /*@ts2dart_const*/
|
||||
[ApplicationRef, ComponentResolver, RouterUrlSerializer, RouterOutletMap, Location],
|
||||
[ApplicationRef, ComponentResolver, RouterUrlSerializer, RouterOutletMap, Location],
|
||||
},
|
||||
/*@ts2dart_Provider*/ {provide: RouteSegment, useFactory: routeSegmentFactory, deps: [Router]}
|
||||
];
|
||||
|
||||
export function routerFactory(app: ApplicationRef, componentResolver: ComponentResolver,
|
||||
urlSerializer: RouterUrlSerializer, routerOutletMap: RouterOutletMap,
|
||||
location: Location): Router {
|
||||
export function routerFactory(
|
||||
app: ApplicationRef, componentResolver: ComponentResolver, urlSerializer: RouterUrlSerializer,
|
||||
routerOutletMap: RouterOutletMap, location: Location): Router {
|
||||
if (app.componentTypes.length == 0) {
|
||||
throw new BaseException("Bootstrap at least one component before injecting Router.");
|
||||
throw new BaseException('Bootstrap at least one component before injecting Router.');
|
||||
}
|
||||
// TODO: vsavkin this should not be null
|
||||
let router = new Router(null, app.componentTypes[0], componentResolver, urlSerializer,
|
||||
routerOutletMap, location);
|
||||
let router = new Router(
|
||||
null, app.componentTypes[0], componentResolver, urlSerializer, routerOutletMap, location);
|
||||
app.registerDisposeListener(() => router.dispose());
|
||||
return router;
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
import {UrlSegment, Tree, TreeNode, rootNode, UrlTree} from './segments';
|
||||
import {BaseException} from '@angular/core';
|
||||
import {isBlank, isPresent, RegExpWrapper} from './facade/lang';
|
||||
|
||||
import {RegExpWrapper, isBlank, isPresent} from './facade/lang';
|
||||
import {Tree, TreeNode, UrlSegment, UrlTree, rootNode} from './segments';
|
||||
|
||||
|
||||
/**
|
||||
* Defines a way to serialize/deserialize a url tree.
|
||||
@ -36,7 +38,7 @@ function _serializeUrlTreeNode(node: TreeNode<UrlSegment>): string {
|
||||
function _serializeUrlTreeNodes(nodes: TreeNode<UrlSegment>[]): string {
|
||||
let main = nodes[0].value.toString();
|
||||
let auxNodes = nodes.slice(1);
|
||||
let aux = auxNodes.length > 0 ? `(${auxNodes.map(_serializeUrlTreeNode).join("//")})` : "";
|
||||
let aux = auxNodes.length > 0 ? `(${auxNodes.map(_serializeUrlTreeNode).join("//")})` : '';
|
||||
let children = _serializeChildren(nodes[0]);
|
||||
return `${main}${aux}${children}`;
|
||||
}
|
||||
@ -45,7 +47,7 @@ function _serializeChildren(node: TreeNode<UrlSegment>): string {
|
||||
if (node.children.length > 0) {
|
||||
return `/${_serializeUrlTreeNodes(node.children)}`;
|
||||
} else {
|
||||
return "";
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
@ -97,8 +99,8 @@ class _UrlParser {
|
||||
this.capture(path);
|
||||
|
||||
|
||||
if (path.indexOf(":") > -1) {
|
||||
let parts = path.split(":");
|
||||
if (path.indexOf(':') > -1) {
|
||||
let parts = path.split(':');
|
||||
outletName = parts[0];
|
||||
path = parts[1];
|
||||
}
|
||||
@ -150,7 +152,7 @@ class _UrlParser {
|
||||
return;
|
||||
}
|
||||
this.capture(key);
|
||||
var value: any = "true";
|
||||
var value: any = 'true';
|
||||
if (this.peekStartsWith('=')) {
|
||||
this.capture('=');
|
||||
var valueMatch = matchUrlSegment(this._remaining);
|
||||
@ -169,7 +171,7 @@ class _UrlParser {
|
||||
return;
|
||||
}
|
||||
this.capture(key);
|
||||
var value: any = "true";
|
||||
var value: any = 'true';
|
||||
if (this.peekStartsWith('=')) {
|
||||
this.capture('=');
|
||||
var valueMatch = matchUrlQueryParamValue(this._remaining);
|
||||
@ -187,7 +189,7 @@ class _UrlParser {
|
||||
this.capture('(');
|
||||
|
||||
while (!this.peekStartsWith(')') && this._remaining.length > 0) {
|
||||
segments = segments.concat(this.parseSegments("aux"));
|
||||
segments = segments.concat(this.parseSegments('aux'));
|
||||
if (this.peekStartsWith('//')) {
|
||||
this.capture('//');
|
||||
}
|
||||
|
@ -1,7 +1,8 @@
|
||||
import {ComponentFactory, Type} from '@angular/core';
|
||||
import {StringMapWrapper, ListWrapper} from './facade/collection';
|
||||
import {isBlank, isPresent, stringify, NumberWrapper} from './facade/lang';
|
||||
|
||||
import {DEFAULT_OUTLET_NAME} from './constants';
|
||||
import {ListWrapper, StringMapWrapper} from './facade/collection';
|
||||
import {NumberWrapper, isBlank, isPresent, stringify} from './facade/lang';
|
||||
|
||||
export class Tree<T> {
|
||||
/** @internal */
|
||||
@ -81,18 +82,19 @@ export class TreeNode<T> {
|
||||
}
|
||||
|
||||
export class UrlSegment {
|
||||
constructor(public segment: any, public parameters: {[key: string]: string},
|
||||
public outlet: string) {}
|
||||
constructor(
|
||||
public segment: any, public parameters: {[key: string]: string}, public outlet: string) {}
|
||||
|
||||
toString(): string {
|
||||
let outletPrefix = isBlank(this.outlet) ? "" : `${this.outlet}:`;
|
||||
let outletPrefix = isBlank(this.outlet) ? '' : `${this.outlet}:`;
|
||||
return `${outletPrefix}${this.segment}${_serializeParams(this.parameters)}`;
|
||||
}
|
||||
}
|
||||
|
||||
function _serializeParams(params: {[key: string]: string}): string {
|
||||
let res = "";
|
||||
StringMapWrapper.forEach(params, (v: any /** TODO #9100 */, k: any /** TODO #9100 */) => res += `;${k}=${v}`);
|
||||
let res = '';
|
||||
StringMapWrapper.forEach(
|
||||
params, (v: any /** TODO #9100 */, k: any /** TODO #9100 */) => res += `;${k}=${v}`);
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -103,8 +105,9 @@ export class RouteSegment {
|
||||
/** @internal */
|
||||
_componentFactory: ComponentFactory<any>;
|
||||
|
||||
constructor(public urlSegments: UrlSegment[], public parameters: {[key: string]: string},
|
||||
public outlet: string, type: Type, componentFactory: ComponentFactory<any>) {
|
||||
constructor(
|
||||
public urlSegments: UrlSegment[], public parameters: {[key: string]: string},
|
||||
public outlet: string, type: Type, componentFactory: ComponentFactory<any>) {
|
||||
this._type = type;
|
||||
this._componentFactory = componentFactory;
|
||||
}
|
||||
@ -119,11 +122,11 @@ export class RouteSegment {
|
||||
|
||||
get type(): Type { return this._type; }
|
||||
|
||||
get stringifiedUrlSegments(): string { return this.urlSegments.map(s => s.toString()).join("/"); }
|
||||
get stringifiedUrlSegments(): string { return this.urlSegments.map(s => s.toString()).join('/'); }
|
||||
}
|
||||
|
||||
export function createEmptyRouteTree(type: Type): RouteTree {
|
||||
let root = new RouteSegment([new UrlSegment("", {}, null)], {}, DEFAULT_OUTLET_NAME, type, null);
|
||||
let root = new RouteSegment([new UrlSegment('', {}, null)], {}, DEFAULT_OUTLET_NAME, type, null);
|
||||
return new RouteTree(new TreeNode<RouteSegment>(root, []));
|
||||
}
|
||||
|
||||
@ -133,7 +136,7 @@ export function serializeRouteSegmentTree(tree: RouteTree): string {
|
||||
|
||||
function _serializeRouteSegmentTree(node: TreeNode<RouteSegment>): string {
|
||||
let v = node.value;
|
||||
let children = node.children.map(c => _serializeRouteSegmentTree(c)).join(", ");
|
||||
let children = node.children.map(c => _serializeRouteSegmentTree(c)).join(', ');
|
||||
return `${v.outlet}:${v.stringifiedUrlSegments}(${stringify(v.type)}) [${children}]`;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user