
committed by
Miško Hevery

parent
4415855683
commit
e916836261
@ -3,7 +3,6 @@ import {
|
||||
MapWrapper,
|
||||
StringMap,
|
||||
StringMapWrapper,
|
||||
List,
|
||||
ListWrapper
|
||||
} from 'angular2/src/core/facade/collection';
|
||||
import {isPresent, isBlank, normalizeBlank, Type} from 'angular2/src/core/facade/lang';
|
||||
@ -42,7 +41,7 @@ export class Instruction {
|
||||
*/
|
||||
export class PrimaryInstruction {
|
||||
constructor(public component: ComponentInstruction, public child: PrimaryInstruction,
|
||||
public auxUrls: List<Url>) {}
|
||||
public auxUrls: Url[]) {}
|
||||
}
|
||||
|
||||
export function stringifyInstruction(instruction: Instruction): string {
|
||||
@ -93,7 +92,7 @@ function stringifyAux(instruction: Instruction): string {
|
||||
export class ComponentInstruction {
|
||||
reuse: boolean = false;
|
||||
|
||||
constructor(public urlPath: string, public urlParams: List<string>,
|
||||
constructor(public urlPath: string, public urlParams: string[],
|
||||
private _recognizer: PathRecognizer, public params: StringMap<string, any> = null) {}
|
||||
|
||||
get componentType() { return this._recognizer.handler.componentType; }
|
||||
|
@ -12,7 +12,6 @@ import {
|
||||
MapWrapper,
|
||||
StringMap,
|
||||
StringMapWrapper,
|
||||
List,
|
||||
ListWrapper
|
||||
} from 'angular2/src/core/facade/collection';
|
||||
|
||||
@ -149,7 +148,7 @@ function parsePathString(route: string): StringMap<string, any> {
|
||||
|
||||
// this function is used to determine whether a route config path like `/foo/:id` collides with
|
||||
// `/foo/:name`
|
||||
function pathDslHash(segments: List<Segment>): string {
|
||||
function pathDslHash(segments: Segment[]): string {
|
||||
return segments.map((segment) => {
|
||||
if (segment instanceof StarSegment) {
|
||||
return '*';
|
||||
@ -164,7 +163,7 @@ function pathDslHash(segments: List<Segment>): string {
|
||||
.join('/');
|
||||
}
|
||||
|
||||
function splitBySlash(url: string): List<string> {
|
||||
function splitBySlash(url: string): string[] {
|
||||
return url.split('/');
|
||||
}
|
||||
|
||||
@ -183,12 +182,12 @@ function assertPath(path: string) {
|
||||
|
||||
export class PathMatch {
|
||||
constructor(public instruction: ComponentInstruction, public remaining: Url,
|
||||
public remainingAux: List<Url>) {}
|
||||
public remainingAux: Url[]) {}
|
||||
}
|
||||
|
||||
// represents something like '/foo/:bar'
|
||||
export class PathRecognizer {
|
||||
private _segments: List<Segment>;
|
||||
private _segments: Segment[];
|
||||
specificity: number;
|
||||
terminal: boolean = true;
|
||||
hash: string;
|
||||
@ -297,7 +296,7 @@ export class PathRecognizer {
|
||||
return this._getInstruction(urlPath, urlParams, this, params);
|
||||
}
|
||||
|
||||
private _getInstruction(urlPath: string, urlParams: List<string>, _recognizer: PathRecognizer,
|
||||
private _getInstruction(urlPath: string, urlParams: string[], _recognizer: PathRecognizer,
|
||||
params: StringMap<string, any>): ComponentInstruction {
|
||||
var hashKey = urlPath + '?' + urlParams.join('?');
|
||||
if (this.cache.has(hashKey)) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import {Promise, PromiseWrapper} from 'angular2/src/core/facade/async';
|
||||
import {List, ListWrapper} from 'angular2/src/core/facade/collection';
|
||||
import {ListWrapper} from 'angular2/src/core/facade/collection';
|
||||
import {Instruction} from './instruction';
|
||||
import {Injectable} from 'angular2/di';
|
||||
|
||||
@ -9,7 +9,7 @@ import {Injectable} from 'angular2/di';
|
||||
*/
|
||||
@Injectable()
|
||||
export class Pipeline {
|
||||
steps: List<Function>;
|
||||
steps: Function[];
|
||||
|
||||
constructor() { this.steps = [instruction => instruction.router.activateOutlets(instruction)]; }
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
import {RouteConfig as RouteConfigAnnotation, RouteDefinition} from './route_config_impl';
|
||||
import {makeDecorator} from 'angular2/src/core/util/decorators';
|
||||
import {List} from 'angular2/src/core/facade/collection';
|
||||
|
||||
export {Route, Redirect, AuxRoute, AsyncRoute, RouteDefinition} from './route_config_impl';
|
||||
export var RouteConfig: (configs: List<RouteDefinition>) => ClassDecorator =
|
||||
export var RouteConfig: (configs: RouteDefinition[]) => ClassDecorator =
|
||||
makeDecorator(RouteConfigAnnotation);
|
||||
|
@ -1,5 +1,4 @@
|
||||
import {CONST, Type} from 'angular2/src/core/facade/lang';
|
||||
import {List} from 'angular2/src/core/facade/collection';
|
||||
import {RouteDefinition} from './route_definition';
|
||||
export {RouteDefinition} from './route_definition';
|
||||
|
||||
@ -14,7 +13,7 @@ export {RouteDefinition} from './route_definition';
|
||||
*/
|
||||
@CONST()
|
||||
export class RouteConfig {
|
||||
constructor(public configs: List<RouteDefinition>) {}
|
||||
constructor(public configs: RouteDefinition[]) {}
|
||||
}
|
||||
|
||||
|
||||
|
@ -12,7 +12,6 @@ import {
|
||||
import {
|
||||
Map,
|
||||
MapWrapper,
|
||||
List,
|
||||
ListWrapper,
|
||||
StringMap,
|
||||
StringMapWrapper
|
||||
@ -37,10 +36,10 @@ export class RouteRecognizer {
|
||||
auxRoutes: Map<string, PathRecognizer> = new Map();
|
||||
|
||||
// TODO: optimize this into a trie
|
||||
matchers: List<PathRecognizer> = [];
|
||||
matchers: PathRecognizer[] = [];
|
||||
|
||||
// TODO: optimize this into a trie
|
||||
redirects: List<Redirector> = [];
|
||||
redirects: Redirector[] = [];
|
||||
|
||||
config(config: RouteDefinition): boolean {
|
||||
var handler;
|
||||
@ -83,7 +82,7 @@ export class RouteRecognizer {
|
||||
* Given a URL, returns a list of `RouteMatch`es, which are partial recognitions for some route.
|
||||
*
|
||||
*/
|
||||
recognize(urlParse: Url): List<PathMatch> {
|
||||
recognize(urlParse: Url): PathMatch[] {
|
||||
var solutions = [];
|
||||
|
||||
urlParse = this._redirect(urlParse);
|
||||
@ -131,8 +130,8 @@ export class RouteRecognizer {
|
||||
}
|
||||
|
||||
export class Redirector {
|
||||
segments: List<string> = [];
|
||||
toSegments: List<string> = [];
|
||||
segments: string[] = [];
|
||||
toSegments: string[] = [];
|
||||
|
||||
constructor(path: string, redirectTo: string) {
|
||||
if (path.startsWith('/')) {
|
||||
|
@ -2,7 +2,6 @@ import {PathMatch} from './path_recognizer';
|
||||
import {RouteRecognizer} from './route_recognizer';
|
||||
import {Instruction, ComponentInstruction, PrimaryInstruction} from './instruction';
|
||||
import {
|
||||
List,
|
||||
ListWrapper,
|
||||
Map,
|
||||
MapWrapper,
|
||||
@ -198,7 +197,7 @@ export class RouteRegistry {
|
||||
* Given a normalized list with component names and params like: `['user', {id: 3 }]`
|
||||
* generates a url with a leading slash relative to the provided `parentComponent`.
|
||||
*/
|
||||
generate(linkParams: List<any>, parentComponent: any): Instruction {
|
||||
generate(linkParams: any[], parentComponent: any): Instruction {
|
||||
let segments = [];
|
||||
let componentCursor = parentComponent;
|
||||
|
||||
@ -283,7 +282,7 @@ export class RouteRegistry {
|
||||
/*
|
||||
* Given a list of instructions, returns the most specific instruction
|
||||
*/
|
||||
function mostSpecific(instructions: List<PrimaryInstruction>): PrimaryInstruction {
|
||||
function mostSpecific(instructions: PrimaryInstruction[]): PrimaryInstruction {
|
||||
return ListWrapper.maximum(
|
||||
instructions, (instruction: PrimaryInstruction) => instruction.component.specificity);
|
||||
}
|
||||
|
@ -4,13 +4,7 @@ import {
|
||||
EventEmitter,
|
||||
ObservableWrapper
|
||||
} from 'angular2/src/core/facade/async';
|
||||
import {
|
||||
Map,
|
||||
StringMapWrapper,
|
||||
MapWrapper,
|
||||
List,
|
||||
ListWrapper
|
||||
} from 'angular2/src/core/facade/collection';
|
||||
import {Map, StringMapWrapper, MapWrapper, ListWrapper} from 'angular2/src/core/facade/collection';
|
||||
import {
|
||||
isBlank,
|
||||
isString,
|
||||
@ -153,7 +147,7 @@ export class Router {
|
||||
* ]);
|
||||
* ```
|
||||
*/
|
||||
config(definitions: List<RouteDefinition>): Promise<any> {
|
||||
config(definitions: RouteDefinition[]): Promise<any> {
|
||||
definitions.forEach(
|
||||
(routeDefinition) => { this.registry.config(this.hostComponent, routeDefinition); });
|
||||
return this.renavigate();
|
||||
@ -222,7 +216,7 @@ export class Router {
|
||||
// we begin navigation. The method below simply traverses instructions and resolves any components
|
||||
// for which `componentType` is not present
|
||||
_settleInstruction(instruction: Instruction): Promise<any> {
|
||||
var unsettledInstructions: List<Promise<any>> = [];
|
||||
var unsettledInstructions: Array<Promise<any>> = [];
|
||||
if (isBlank(instruction.component.componentType)) {
|
||||
unsettledInstructions.push(instruction.component.resolveComponentType());
|
||||
}
|
||||
@ -387,7 +381,7 @@ export class Router {
|
||||
* Generate a URL from a component name and optional map of parameters. The URL is relative to the
|
||||
* app's base href.
|
||||
*/
|
||||
generate(linkParams: List<any>): Instruction {
|
||||
generate(linkParams: any[]): Instruction {
|
||||
let normalizedLinkParams = splitAndFlattenLinkParams(linkParams);
|
||||
|
||||
var first = ListWrapper.first(normalizedLinkParams);
|
||||
@ -494,10 +488,10 @@ class ChildRouter extends Router {
|
||||
* Returns: ['', 'a', 'b', {c: 2}]
|
||||
*/
|
||||
var SLASH = new RegExp('/');
|
||||
function splitAndFlattenLinkParams(linkParams: List<any>): List<any> {
|
||||
function splitAndFlattenLinkParams(linkParams: any[]): any[] {
|
||||
return ListWrapper.reduce(linkParams, (accumulation, item) => {
|
||||
if (isString(item)) {
|
||||
return ListWrapper.concat(accumulation, StringWrapper.split(item, SLASH));
|
||||
return accumulation.concat(StringWrapper.split(item, SLASH));
|
||||
}
|
||||
accumulation.push(item);
|
||||
return accumulation;
|
||||
|
@ -1,5 +1,5 @@
|
||||
import {Directive} from '../core/metadata';
|
||||
import {List, StringMap, StringMapWrapper} from 'angular2/src/core/facade/collection';
|
||||
import {StringMap, StringMapWrapper} from 'angular2/src/core/facade/collection';
|
||||
|
||||
import {Router} from './router';
|
||||
import {Location} from './location';
|
||||
@ -44,7 +44,7 @@ import {Instruction, stringifyInstruction} from './instruction';
|
||||
}
|
||||
})
|
||||
export class RouterLink {
|
||||
private _routeParams: List<any>;
|
||||
private _routeParams: any[];
|
||||
|
||||
// the url displayed on the anchor element.
|
||||
visibleHref: string;
|
||||
@ -56,7 +56,7 @@ export class RouterLink {
|
||||
|
||||
get isRouteActive(): boolean { return this._router.isRouteActive(this._navigationInstruction); }
|
||||
|
||||
set routeParams(changes: List<any>) {
|
||||
set routeParams(changes: any[]) {
|
||||
this._routeParams = changes;
|
||||
this._navigationInstruction = this._router.generate(this._routeParams);
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import {List, StringMap, StringMapWrapper} from 'angular2/src/core/facade/collection';
|
||||
import {StringMap, StringMapWrapper} from 'angular2/src/core/facade/collection';
|
||||
import {
|
||||
isPresent,
|
||||
isBlank,
|
||||
@ -12,7 +12,7 @@ import {
|
||||
*/
|
||||
export class Url {
|
||||
constructor(public path: string, public child: Url = null,
|
||||
public auxiliary: List<Url> = CONST_EXPR([]),
|
||||
public auxiliary: Url[] = CONST_EXPR([]),
|
||||
public params: StringMap<string, any> = null) {}
|
||||
|
||||
toString(): string {
|
||||
@ -39,7 +39,7 @@ export class Url {
|
||||
}
|
||||
|
||||
export class RootUrl extends Url {
|
||||
constructor(path: string, child: Url = null, auxiliary: List<Url> = CONST_EXPR([]),
|
||||
constructor(path: string, child: Url = null, auxiliary: Url[] = CONST_EXPR([]),
|
||||
params: StringMap<string, any> = null) {
|
||||
super(path, child, auxiliary, params);
|
||||
}
|
||||
@ -59,7 +59,7 @@ export class RootUrl extends Url {
|
||||
}
|
||||
}
|
||||
|
||||
export function pathSegmentsToUrl(pathSegments: List<string>): Url {
|
||||
export function pathSegmentsToUrl(pathSegments: string[]): Url {
|
||||
var url = new Url(pathSegments[pathSegments.length - 1]);
|
||||
for (var i = pathSegments.length - 2; i >= 0; i -= 1) {
|
||||
url = new Url(pathSegments[i], url);
|
||||
@ -187,7 +187,7 @@ export class UrlParser {
|
||||
params[key] = value;
|
||||
}
|
||||
|
||||
parseAuxiliaryRoutes(): List<Url> {
|
||||
parseAuxiliaryRoutes(): Url[] {
|
||||
var routes = [];
|
||||
this.capture('(');
|
||||
|
||||
@ -205,7 +205,7 @@ export class UrlParser {
|
||||
|
||||
export var parser = new UrlParser();
|
||||
|
||||
export function serializeParams(paramMap: StringMap<string, any>): List<string> {
|
||||
export function serializeParams(paramMap: StringMap<string, any>): string[] {
|
||||
var params = [];
|
||||
if (isPresent(paramMap)) {
|
||||
StringMapWrapper.forEach(paramMap, (value, key) => {
|
||||
|
Reference in New Issue
Block a user