style(lint): re-format modules/@angular
This commit is contained in:
@ -1,8 +1,10 @@
|
||||
import {Directive} from '@angular/core';
|
||||
import {Location} from '@angular/common';
|
||||
import {Directive} from '@angular/core';
|
||||
|
||||
import {isString} from '../facade/lang';
|
||||
import {Router} from '../router';
|
||||
import {Instruction} from '../instruction';
|
||||
import {Router} from '../router';
|
||||
|
||||
|
||||
/**
|
||||
* The RouterLink directive lets you link to specific parts of your app.
|
||||
|
@ -1,22 +1,13 @@
|
||||
import {PromiseWrapper, EventEmitter} from '../facade/async';
|
||||
import {Attribute, ComponentRef, Directive, DynamicComponentLoader, OnDestroy, Output, ReflectiveInjector, ViewContainerRef, provide} from '@angular/core';
|
||||
|
||||
import {EventEmitter, PromiseWrapper} from '../facade/async';
|
||||
import {StringMapWrapper} from '../facade/collection';
|
||||
import {isBlank, isPresent} from '../facade/lang';
|
||||
import {
|
||||
Directive,
|
||||
Attribute,
|
||||
DynamicComponentLoader,
|
||||
ComponentRef,
|
||||
ViewContainerRef,
|
||||
provide,
|
||||
ReflectiveInjector,
|
||||
OnDestroy,
|
||||
Output
|
||||
} from '@angular/core';
|
||||
import * as routerMod from '../router';
|
||||
import {ComponentInstruction, RouteParams, RouteData} from '../instruction';
|
||||
import {ComponentInstruction, RouteData, RouteParams} from '../instruction';
|
||||
import {CanDeactivate, CanReuse, OnActivate, OnDeactivate, OnReuse} from '../interfaces';
|
||||
import * as hookMod from '../lifecycle/lifecycle_annotations';
|
||||
import {hasLifecycleHook} from '../lifecycle/route_lifecycle_reflector';
|
||||
import {OnActivate, CanReuse, OnReuse, OnDeactivate, CanDeactivate} from '../interfaces';
|
||||
import * as routerMod from '../router';
|
||||
|
||||
let _resolveToTrue = PromiseWrapper.resolve(true);
|
||||
|
||||
@ -37,8 +28,9 @@ export class RouterOutlet implements OnDestroy {
|
||||
|
||||
@Output('activate') public activateEvents = new EventEmitter<any>();
|
||||
|
||||
constructor(private _viewContainerRef: ViewContainerRef, private _loader: DynamicComponentLoader,
|
||||
private _parentRouter: routerMod.Router, @Attribute('name') nameAttr: string) {
|
||||
constructor(
|
||||
private _viewContainerRef: ViewContainerRef, private _loader: DynamicComponentLoader,
|
||||
private _parentRouter: routerMod.Router, @Attribute('name') nameAttr: string) {
|
||||
if (isPresent(nameAttr)) {
|
||||
this.name = nameAttr;
|
||||
this._parentRouter.registerAuxOutlet(this);
|
||||
@ -166,8 +158,8 @@ export class RouterOutlet implements OnDestroy {
|
||||
(<CanReuse>ref.instance).routerCanReuse(nextInstruction, this._currentInstruction));
|
||||
} else {
|
||||
result = nextInstruction == this._currentInstruction ||
|
||||
(isPresent(nextInstruction.params) && isPresent(this._currentInstruction.params) &&
|
||||
StringMapWrapper.equals(nextInstruction.params, this._currentInstruction.params));
|
||||
(isPresent(nextInstruction.params) && isPresent(this._currentInstruction.params) &&
|
||||
StringMapWrapper.equals(nextInstruction.params, this._currentInstruction.params));
|
||||
}
|
||||
return <Promise<boolean>>PromiseWrapper.resolve(result);
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
import {StringMapWrapper} from '../src/facade/collection';
|
||||
import {isPresent, isBlank, normalizeBlank} from '../src/facade/lang';
|
||||
import {PromiseWrapper} from '../src/facade/async';
|
||||
import {StringMapWrapper} from '../src/facade/collection';
|
||||
import {isBlank, isPresent, normalizeBlank} from '../src/facade/lang';
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@ -111,8 +112,9 @@ export var BLANK_ROUTE_DATA = new RouteData();
|
||||
* ```
|
||||
*/
|
||||
export abstract class Instruction {
|
||||
constructor(public component: ComponentInstruction, public child: Instruction,
|
||||
public auxInstruction: {[key: string]: Instruction}) {}
|
||||
constructor(
|
||||
public component: ComponentInstruction, public child: Instruction,
|
||||
public auxInstruction: {[key: string]: Instruction}) {}
|
||||
|
||||
get urlPath(): string { return isPresent(this.component) ? this.component.urlPath : ''; }
|
||||
|
||||
@ -139,7 +141,7 @@ export abstract class Instruction {
|
||||
/** @internal */
|
||||
_toNonRootUrl(): string {
|
||||
return this._stringifyPathMatrixAuxPrefixed() +
|
||||
(isPresent(this.child) ? this.child._toNonRootUrl() : '');
|
||||
(isPresent(this.child) ? this.child._toNonRootUrl() : '');
|
||||
}
|
||||
|
||||
toUrlQuery(): string { return this.urlParams.length > 0 ? ('?' + this.urlParams.join('&')) : ''; }
|
||||
@ -157,20 +159,20 @@ export abstract class Instruction {
|
||||
*/
|
||||
toUrlPath(): string {
|
||||
return this.urlPath + this._stringifyAux() +
|
||||
(isPresent(this.child) ? this.child._toNonRootUrl() : '');
|
||||
(isPresent(this.child) ? this.child._toNonRootUrl() : '');
|
||||
}
|
||||
|
||||
// default instructions override these
|
||||
toLinkUrl(): string {
|
||||
return this.urlPath + this._stringifyAux() +
|
||||
(isPresent(this.child) ? this.child._toLinkUrl() : '') + this.toUrlQuery();
|
||||
(isPresent(this.child) ? this.child._toLinkUrl() : '') + this.toUrlQuery();
|
||||
}
|
||||
|
||||
// this is the non-root version (called recursively)
|
||||
/** @internal */
|
||||
_toLinkUrl(): string {
|
||||
return this._stringifyPathMatrixAuxPrefixed() +
|
||||
(isPresent(this.child) ? this.child._toLinkUrl() : '');
|
||||
(isPresent(this.child) ? this.child._toLinkUrl() : '');
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
@ -213,8 +215,9 @@ export abstract class Instruction {
|
||||
* a resolved instruction has an outlet instruction for itself, but maybe not for...
|
||||
*/
|
||||
export class ResolvedInstruction extends Instruction {
|
||||
constructor(component: ComponentInstruction, child: Instruction,
|
||||
auxInstruction: {[key: string]: Instruction}) {
|
||||
constructor(
|
||||
component: ComponentInstruction, child: Instruction,
|
||||
auxInstruction: {[key: string]: Instruction}) {
|
||||
super(component, child, auxInstruction);
|
||||
}
|
||||
|
||||
@ -243,8 +246,9 @@ export class DefaultInstruction extends ResolvedInstruction {
|
||||
* Represents a component that may need to do some redirection or lazy loading at a later time.
|
||||
*/
|
||||
export class UnresolvedInstruction extends Instruction {
|
||||
constructor(private _resolver: () => Promise<Instruction>, private _urlPath: string = '',
|
||||
private _urlParams: string[] = /*@ts2dart_const*/[]) {
|
||||
constructor(
|
||||
private _resolver: () => Promise<Instruction>, private _urlPath: string = '',
|
||||
private _urlParams: string[] = /*@ts2dart_const*/[]) {
|
||||
super(null, null, {});
|
||||
}
|
||||
|
||||
@ -281,8 +285,9 @@ export class UnresolvedInstruction extends Instruction {
|
||||
|
||||
|
||||
export class RedirectInstruction extends ResolvedInstruction {
|
||||
constructor(component: ComponentInstruction, child: Instruction,
|
||||
auxInstruction: {[key: string]: Instruction}, private _specificity: string) {
|
||||
constructor(
|
||||
component: ComponentInstruction, child: Instruction,
|
||||
auxInstruction: {[key: string]: Instruction}, private _specificity: string) {
|
||||
super(component, child, auxInstruction);
|
||||
}
|
||||
|
||||
@ -309,9 +314,11 @@ export class ComponentInstruction {
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
constructor(public urlPath: string, public urlParams: string[], data: RouteData,
|
||||
public componentType: any /** TODO #9100 */, public terminal: boolean, public specificity: string,
|
||||
public params: {[key: string]: string} = null, public routeName: string) {
|
||||
constructor(
|
||||
public urlPath: string, public urlParams: string[], data: RouteData,
|
||||
public componentType: any /** TODO #9100 */, public terminal: boolean,
|
||||
public specificity: string, public params: {[key: string]: string} = null,
|
||||
public routeName: string) {
|
||||
this.routeData = isPresent(data) ? data : BLANK_ROUTE_DATA;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
import {ComponentInstruction} from './instruction';
|
||||
import {global} from '../src/facade/lang';
|
||||
|
||||
import {ComponentInstruction} from './instruction';
|
||||
|
||||
|
||||
// This is here only so that after TS transpilation the file is not empty.
|
||||
// TODO(rado): find a better way to fix this, or remove if likely culprit
|
||||
// https://github.com/systemjs/systemjs/issues/487 gets closed.
|
||||
@ -26,9 +28,8 @@ var __make_dart_analyzer_happy: Promise<any> = null;
|
||||
* {@example router/ts/on_activate/on_activate_example.ts region='routerOnActivate'}
|
||||
*/
|
||||
export interface OnActivate {
|
||||
routerOnActivate(nextInstruction: ComponentInstruction,
|
||||
prevInstruction: ComponentInstruction): any |
|
||||
Promise<any>;
|
||||
routerOnActivate(nextInstruction: ComponentInstruction, prevInstruction: ComponentInstruction):
|
||||
any|Promise<any>;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -47,8 +48,8 @@ export interface OnActivate {
|
||||
* {@example router/ts/reuse/reuse_example.ts region='reuseCmp'}
|
||||
*/
|
||||
export interface OnReuse {
|
||||
routerOnReuse(nextInstruction: ComponentInstruction, prevInstruction: ComponentInstruction): any |
|
||||
Promise<any>;
|
||||
routerOnReuse(nextInstruction: ComponentInstruction, prevInstruction: ComponentInstruction): any
|
||||
|Promise<any>;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -67,9 +68,8 @@ export interface OnReuse {
|
||||
* {@example router/ts/on_deactivate/on_deactivate_example.ts region='routerOnDeactivate'}
|
||||
*/
|
||||
export interface OnDeactivate {
|
||||
routerOnDeactivate(nextInstruction: ComponentInstruction,
|
||||
prevInstruction: ComponentInstruction): any |
|
||||
Promise<any>;
|
||||
routerOnDeactivate(nextInstruction: ComponentInstruction, prevInstruction: ComponentInstruction):
|
||||
any|Promise<any>;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -93,9 +93,8 @@ export interface OnDeactivate {
|
||||
* {@example router/ts/reuse/reuse_example.ts region='reuseCmp'}
|
||||
*/
|
||||
export interface CanReuse {
|
||||
routerCanReuse(nextInstruction: ComponentInstruction,
|
||||
prevInstruction: ComponentInstruction): boolean |
|
||||
Promise<boolean>;
|
||||
routerCanReuse(nextInstruction: ComponentInstruction, prevInstruction: ComponentInstruction):
|
||||
boolean|Promise<boolean>;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -118,7 +117,6 @@ export interface CanReuse {
|
||||
* {@example router/ts/can_deactivate/can_deactivate_example.ts region='routerCanDeactivate'}
|
||||
*/
|
||||
export interface CanDeactivate {
|
||||
routerCanDeactivate(nextInstruction: ComponentInstruction,
|
||||
prevInstruction: ComponentInstruction): boolean |
|
||||
Promise<boolean>;
|
||||
routerCanDeactivate(nextInstruction: ComponentInstruction, prevInstruction: ComponentInstruction):
|
||||
boolean|Promise<boolean>;
|
||||
}
|
||||
|
@ -4,16 +4,12 @@
|
||||
*/
|
||||
|
||||
import {makeDecorator} from '../../core_private';
|
||||
import {CanActivate as CanActivateAnnotation} from './lifecycle_annotations_impl';
|
||||
import {ComponentInstruction} from '../instruction';
|
||||
|
||||
export {
|
||||
routerCanReuse,
|
||||
routerCanDeactivate,
|
||||
routerOnActivate,
|
||||
routerOnReuse,
|
||||
routerOnDeactivate
|
||||
} from './lifecycle_annotations_impl';
|
||||
import {CanActivate as CanActivateAnnotation} from './lifecycle_annotations_impl';
|
||||
|
||||
export {routerCanDeactivate, routerCanReuse, routerOnActivate, routerOnDeactivate, routerOnReuse} from './lifecycle_annotations_impl';
|
||||
|
||||
|
||||
/**
|
||||
* Defines route lifecycle hook `CanActivate`, which is called by the router to determine
|
||||
@ -41,6 +37,6 @@ export {
|
||||
*
|
||||
* {@example router/ts/can_activate/can_activate_example.ts region='canActivate' }
|
||||
*/
|
||||
export var CanActivate: (hook: (next: ComponentInstruction, prev: ComponentInstruction) =>
|
||||
Promise<boolean>| boolean) => ClassDecorator =
|
||||
makeDecorator(CanActivateAnnotation);
|
||||
export var CanActivate:
|
||||
(hook: (next: ComponentInstruction, prev: ComponentInstruction) => Promise<boolean>| boolean) =>
|
||||
ClassDecorator = makeDecorator(CanActivateAnnotation);
|
||||
|
@ -10,12 +10,12 @@ export class CanActivate {
|
||||
}
|
||||
|
||||
export const routerCanReuse: RouteLifecycleHook =
|
||||
/*@ts2dart_const*/ new RouteLifecycleHook("routerCanReuse");
|
||||
/*@ts2dart_const*/ new RouteLifecycleHook('routerCanReuse');
|
||||
export const routerCanDeactivate: RouteLifecycleHook =
|
||||
/*@ts2dart_const*/ new RouteLifecycleHook("routerCanDeactivate");
|
||||
/*@ts2dart_const*/ new RouteLifecycleHook('routerCanDeactivate');
|
||||
export const routerOnActivate: RouteLifecycleHook =
|
||||
/*@ts2dart_const*/ new RouteLifecycleHook("routerOnActivate");
|
||||
/*@ts2dart_const*/ new RouteLifecycleHook('routerOnActivate');
|
||||
export const routerOnReuse: RouteLifecycleHook =
|
||||
/*@ts2dart_const*/ new RouteLifecycleHook("routerOnReuse");
|
||||
/*@ts2dart_const*/ new RouteLifecycleHook('routerOnReuse');
|
||||
export const routerOnDeactivate: RouteLifecycleHook =
|
||||
/*@ts2dart_const*/ new RouteLifecycleHook("routerOnDeactivate");
|
||||
/*@ts2dart_const*/ new RouteLifecycleHook('routerOnDeactivate');
|
||||
|
@ -1,10 +1,12 @@
|
||||
import {Type} from '@angular/core';
|
||||
import {RouteLifecycleHook, CanActivate} from './lifecycle_annotations_impl';
|
||||
|
||||
import {reflector} from '../../core_private';
|
||||
|
||||
import {CanActivate, RouteLifecycleHook} from './lifecycle_annotations_impl';
|
||||
|
||||
export function hasLifecycleHook(e: RouteLifecycleHook, type: any /** TODO #9100 */): boolean {
|
||||
if (!(type instanceof Type)) return false;
|
||||
return e.name in(<any>type).prototype;
|
||||
return e.name in (<any>type).prototype;
|
||||
}
|
||||
|
||||
export function getCanActivateHook(type: any /** TODO #9100 */): Function {
|
||||
|
@ -1,7 +1,9 @@
|
||||
import {RouteConfig as RouteConfigAnnotation, RouteDefinition} from './route_config_impl';
|
||||
import {makeDecorator} from '../../core_private';
|
||||
|
||||
export {Route, Redirect, AuxRoute, AsyncRoute, RouteDefinition} from './route_config_impl';
|
||||
import {RouteConfig as RouteConfigAnnotation, RouteDefinition} from './route_config_impl';
|
||||
|
||||
export {AsyncRoute, AuxRoute, Redirect, Route, RouteDefinition} from './route_config_impl';
|
||||
|
||||
|
||||
// Copied from RouteConfig in route_config_impl.
|
||||
/**
|
||||
|
@ -1,9 +1,11 @@
|
||||
import {AsyncRoute, AuxRoute, Route, Redirect, RouteDefinition} from './route_config_decorator';
|
||||
import {ComponentDefinition} from '../route_definition';
|
||||
import {isType, Type} from '../facade/lang';
|
||||
import {BaseException} from '../facade/exceptions';
|
||||
import {Type, isType} from '../facade/lang';
|
||||
import {ComponentDefinition} from '../route_definition';
|
||||
import {RouteRegistry} from '../route_registry';
|
||||
|
||||
import {AsyncRoute, AuxRoute, Redirect, Route, RouteDefinition} from './route_config_decorator';
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Given a JS Object that represents a route config, returns a corresponding Route, AsyncRoute,
|
||||
@ -12,8 +14,8 @@ import {RouteRegistry} from '../route_registry';
|
||||
* Also wraps an AsyncRoute's loader function to add the loaded component's route config to the
|
||||
* `RouteRegistry`.
|
||||
*/
|
||||
export function normalizeRouteConfig(config: RouteDefinition,
|
||||
registry: RouteRegistry): RouteDefinition {
|
||||
export function normalizeRouteConfig(
|
||||
config: RouteDefinition, registry: RouteRegistry): RouteDefinition {
|
||||
if (config instanceof AsyncRoute) {
|
||||
var wrappedLoader = wrapLoaderToReconfigureRegistry(config.loader, registry);
|
||||
return new AsyncRoute({
|
||||
@ -44,7 +46,7 @@ export function normalizeRouteConfig(config: RouteDefinition,
|
||||
});
|
||||
}
|
||||
if (config.aux) {
|
||||
return new AuxRoute({path: config.aux, component:<Type>config.component, name: config.name});
|
||||
return new AuxRoute({path: config.aux, component: <Type>config.component, name: config.name});
|
||||
}
|
||||
if (config.component) {
|
||||
if (typeof config.component == 'object') {
|
||||
@ -52,7 +54,7 @@ export function normalizeRouteConfig(config: RouteDefinition,
|
||||
if (componentDefinitionObject.type == 'constructor') {
|
||||
return new Route({
|
||||
path: config.path,
|
||||
component:<Type>componentDefinitionObject.constructor,
|
||||
component: <Type>componentDefinitionObject.constructor,
|
||||
name: config.name,
|
||||
data: config.data,
|
||||
useAsDefault: config.useAsDefault
|
||||
|
@ -18,7 +18,7 @@ export interface RouteDefinition {
|
||||
regex?: string;
|
||||
regex_group_names?: string[];
|
||||
serializer?: RegexSerializer;
|
||||
component?: Type | ComponentDefinition;
|
||||
component?: Type|ComponentDefinition;
|
||||
loader?: () => Promise<Type>;
|
||||
redirectTo?: any[];
|
||||
name?: string;
|
||||
|
@ -1,29 +1,13 @@
|
||||
import {ListWrapper, Map, StringMapWrapper} from '../src/facade/collection';
|
||||
import {PromiseWrapper} from '../src/facade/async';
|
||||
import {
|
||||
isPresent,
|
||||
isArray,
|
||||
isBlank,
|
||||
isType,
|
||||
isString,
|
||||
isStringMap,
|
||||
Type,
|
||||
StringWrapper,
|
||||
Math,
|
||||
getTypeNameForDebugging,
|
||||
} from '../src/facade/lang';
|
||||
import {ListWrapper, Map, StringMapWrapper} from '../src/facade/collection';
|
||||
|
||||
import {isPresent, isArray, isBlank, isType, isString, isStringMap, Type, StringWrapper, Math, getTypeNameForDebugging,} from '../src/facade/lang';
|
||||
import {BaseException} from '../src/facade/exceptions';
|
||||
import {Injectable, Inject, OpaqueToken} from '@angular/core';
|
||||
import {RouteConfig, Route, AuxRoute, RouteDefinition} from './route_config/route_config_impl';
|
||||
import {PathMatch, RedirectMatch, RouteMatch} from './rules/rules';
|
||||
import {RuleSet} from './rules/rule_set';
|
||||
import {
|
||||
Instruction,
|
||||
ResolvedInstruction,
|
||||
RedirectInstruction,
|
||||
UnresolvedInstruction,
|
||||
DefaultInstruction
|
||||
} from './instruction';
|
||||
import {Instruction, ResolvedInstruction, RedirectInstruction, UnresolvedInstruction, DefaultInstruction} from './instruction';
|
||||
import {normalizeRouteConfig, assertComponentExists} from './route_config/route_config_normalizer';
|
||||
import {parser, Url, convertUrlParamsToArray} from './url_parser';
|
||||
import {GeneratedUrl} from './rules/route_paths/route_path';
|
||||
@ -152,8 +136,8 @@ export class RouteRegistry {
|
||||
/**
|
||||
* Recognizes all parent-child routes, but creates unresolved auxiliary routes
|
||||
*/
|
||||
private _recognize(parsedUrl: Url, ancestorInstructions: Instruction[],
|
||||
_aux = false): Promise<Instruction> {
|
||||
private _recognize(parsedUrl: Url, ancestorInstructions: Instruction[], _aux = false):
|
||||
Promise<Instruction> {
|
||||
var parentInstruction = ListWrapper.last(ancestorInstructions);
|
||||
var parentComponent = isPresent(parentInstruction) ? parentInstruction.component.componentType :
|
||||
this._rootComponent;
|
||||
@ -202,8 +186,9 @@ export class RouteRegistry {
|
||||
if (candidate instanceof RedirectMatch) {
|
||||
var instruction =
|
||||
this.generate(candidate.redirectTo, ancestorInstructions.concat([null]));
|
||||
return new RedirectInstruction(instruction.component, instruction.child,
|
||||
instruction.auxInstruction, candidate.specificity);
|
||||
return new RedirectInstruction(
|
||||
instruction.component, instruction.child, instruction.auxInstruction,
|
||||
candidate.specificity);
|
||||
}
|
||||
}));
|
||||
|
||||
@ -214,8 +199,8 @@ export class RouteRegistry {
|
||||
return PromiseWrapper.all<Instruction>(matchPromises).then(mostSpecific);
|
||||
}
|
||||
|
||||
private _auxRoutesToUnresolved(auxRoutes: Url[],
|
||||
parentInstructions: Instruction[]): {[key: string]: Instruction} {
|
||||
private _auxRoutesToUnresolved(auxRoutes: Url[], parentInstructions: Instruction[]):
|
||||
{[key: string]: Instruction} {
|
||||
var unresolvedAuxInstructions: {[key: string]: Instruction} = {};
|
||||
|
||||
auxRoutes.forEach((auxUrl: Url) => {
|
||||
@ -281,7 +266,7 @@ export class RouteRegistry {
|
||||
// If both exist, we throw. Otherwise, we prefer whichever exists.
|
||||
var childRouteExists = this.hasRoute(routeName, parentComponentType);
|
||||
var parentRouteExists = isPresent(grandparentComponentType) &&
|
||||
this.hasRoute(routeName, grandparentComponentType);
|
||||
this.hasRoute(routeName, grandparentComponentType);
|
||||
|
||||
if (parentRouteExists && childRouteExists) {
|
||||
let msg =
|
||||
@ -330,8 +315,9 @@ export class RouteRegistry {
|
||||
* `prevInstruction` is the existing instruction that would be replaced, but which might have
|
||||
* aux routes that need to be cloned.
|
||||
*/
|
||||
private _generate(linkParams: any[], ancestorInstructions: Instruction[],
|
||||
prevInstruction: Instruction, _aux = false, _originalLink: any[]): Instruction {
|
||||
private _generate(
|
||||
linkParams: any[], ancestorInstructions: Instruction[], prevInstruction: Instruction,
|
||||
_aux = false, _originalLink: any[]): Instruction {
|
||||
let parentComponentType = this._rootComponent;
|
||||
let componentInstruction: any /** TODO #9100 */ = null;
|
||||
let auxInstructions: {[key: string]: Instruction} = {};
|
||||
@ -394,8 +380,8 @@ export class RouteRegistry {
|
||||
var generatedUrl: GeneratedUrl = routeRecognizer.generateComponentPathValues(routeParams);
|
||||
return new UnresolvedInstruction(() => {
|
||||
return routeRecognizer.handler.resolveComponentType().then((_) => {
|
||||
return this._generate(linkParams, ancestorInstructions, prevInstruction, _aux,
|
||||
_originalLink);
|
||||
return this._generate(
|
||||
linkParams, ancestorInstructions, prevInstruction, _aux, _originalLink);
|
||||
});
|
||||
}, generatedUrl.urlPath, convertUrlParamsToArray(generatedUrl.urlParams));
|
||||
}
|
||||
@ -408,8 +394,8 @@ export class RouteRegistry {
|
||||
// If we have an ancestor instruction, we preserve whatever aux routes are active from it.
|
||||
while (linkParamIndex < linkParams.length && isArray(linkParams[linkParamIndex])) {
|
||||
let auxParentInstruction: Instruction[] = [parentInstruction];
|
||||
let auxInstruction = this._generate(linkParams[linkParamIndex], auxParentInstruction, null,
|
||||
true, _originalLink);
|
||||
let auxInstruction = this._generate(
|
||||
linkParams[linkParamIndex], auxParentInstruction, null, true, _originalLink);
|
||||
|
||||
// TODO: this will not work for aux routes with parameters or multiple segments
|
||||
auxInstructions[auxInstruction.component.urlPath] = auxInstruction;
|
||||
@ -429,8 +415,8 @@ export class RouteRegistry {
|
||||
} else {
|
||||
let childAncestorComponents: Instruction[] = ancestorInstructions.concat([instruction]);
|
||||
let remainingLinkParams = linkParams.slice(linkParamIndex);
|
||||
childInstruction = this._generate(remainingLinkParams, childAncestorComponents, null, false,
|
||||
_originalLink);
|
||||
childInstruction = this._generate(
|
||||
remainingLinkParams, childAncestorComponents, null, false, _originalLink);
|
||||
}
|
||||
instruction.child = childInstruction;
|
||||
}
|
||||
|
@ -1,14 +1,16 @@
|
||||
import {PromiseWrapper, EventEmitter, ObservableWrapper} from '../src/facade/async';
|
||||
import {Map, StringMapWrapper} from '../src/facade/collection';
|
||||
import {isBlank, isPresent, Type} from '../src/facade/lang';
|
||||
import {BaseException} from '../src/facade/exceptions';
|
||||
import {Location} from '@angular/common';
|
||||
import {RouteRegistry, ROUTER_PRIMARY_COMPONENT} from './route_registry';
|
||||
import {ComponentInstruction, Instruction, DefaultInstruction} from './instruction';
|
||||
import {Inject, Injectable} from '@angular/core';
|
||||
|
||||
import {EventEmitter, ObservableWrapper, PromiseWrapper} from '../src/facade/async';
|
||||
import {Map, StringMapWrapper} from '../src/facade/collection';
|
||||
import {BaseException} from '../src/facade/exceptions';
|
||||
import {Type, isBlank, isPresent} from '../src/facade/lang';
|
||||
|
||||
import {RouterOutlet} from './directives/router_outlet';
|
||||
import {ComponentInstruction, DefaultInstruction, Instruction} from './instruction';
|
||||
import {getCanActivateHook} from './lifecycle/route_lifecycle_reflector';
|
||||
import {RouteDefinition} from './route_config/route_config_impl';
|
||||
import {Injectable, Inject} from '@angular/core';
|
||||
import {ROUTER_PRIMARY_COMPONENT, RouteRegistry} from './route_registry';
|
||||
|
||||
let _resolveToTrue = PromiseWrapper.resolve(true);
|
||||
let _resolveToFalse = PromiseWrapper.resolve(false);
|
||||
@ -48,8 +50,9 @@ export class Router {
|
||||
private _subject: EventEmitter<any> = new EventEmitter();
|
||||
|
||||
|
||||
constructor(public registry: RouteRegistry, public parent: Router, public hostComponent: any,
|
||||
public root?: Router) {}
|
||||
constructor(
|
||||
public registry: RouteRegistry, public parent: Router, public hostComponent: any,
|
||||
public root?: Router) {}
|
||||
|
||||
/**
|
||||
* Constructs a child router. You probably don't need to use this unless you're writing a reusable
|
||||
@ -152,11 +155,13 @@ export class Router {
|
||||
return false;
|
||||
}
|
||||
if (isPresent(instruction.component.params)) {
|
||||
StringMapWrapper.forEach(instruction.component.params, (value: any /** TODO #9100 */, key: any /** TODO #9100 */) => {
|
||||
if (currentInstruction.component.params[key] !== value) {
|
||||
reason = false;
|
||||
}
|
||||
});
|
||||
StringMapWrapper.forEach(
|
||||
instruction.component.params,
|
||||
(value: any /** TODO #9100 */, key: any /** TODO #9100 */) => {
|
||||
if (currentInstruction.component.params[key] !== value) {
|
||||
reason = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
currentInstruction = currentInstruction.child;
|
||||
instruction = instruction.child;
|
||||
@ -230,8 +235,8 @@ export class Router {
|
||||
* Navigate via the provided instruction. Returns a promise that resolves when navigation is
|
||||
* complete.
|
||||
*/
|
||||
navigateByInstruction(instruction: Instruction,
|
||||
_skipLocationChange: boolean = false): Promise<any> {
|
||||
navigateByInstruction(instruction: Instruction, _skipLocationChange: boolean = false):
|
||||
Promise<any> {
|
||||
if (isBlank(instruction)) {
|
||||
return _resolveToFalse;
|
||||
}
|
||||
@ -254,9 +259,10 @@ export class Router {
|
||||
unsettledInstructions.push(this._settleInstruction(instruction.child));
|
||||
}
|
||||
|
||||
StringMapWrapper.forEach(instruction.auxInstruction, (instruction: Instruction, _: any /** TODO #9100 */) => {
|
||||
unsettledInstructions.push(this._settleInstruction(instruction));
|
||||
});
|
||||
StringMapWrapper.forEach(
|
||||
instruction.auxInstruction, (instruction: Instruction, _: any /** TODO #9100 */) => {
|
||||
unsettledInstructions.push(this._settleInstruction(instruction));
|
||||
});
|
||||
return PromiseWrapper.all(unsettledInstructions);
|
||||
});
|
||||
}
|
||||
@ -270,16 +276,14 @@ export class Router {
|
||||
if (!result) {
|
||||
return false;
|
||||
}
|
||||
return this._routerCanDeactivate(instruction)
|
||||
.then((result: boolean) => {
|
||||
if (result) {
|
||||
return this.commit(instruction, _skipLocationChange)
|
||||
.then((_) => {
|
||||
this._emitNavigationFinish(instruction.component);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
return this._routerCanDeactivate(instruction).then((result: boolean) => {
|
||||
if (result) {
|
||||
return this.commit(instruction, _skipLocationChange).then((_) => {
|
||||
this._emitNavigationFinish(instruction.component);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@ -309,13 +313,12 @@ export class Router {
|
||||
if (isBlank(instruction.component)) {
|
||||
return _resolveToTrue;
|
||||
}
|
||||
return this._outlet.routerCanReuse(instruction.component)
|
||||
.then((result) => {
|
||||
instruction.component.reuse = result;
|
||||
if (result && isPresent(this._childRouter) && isPresent(instruction.child)) {
|
||||
return this._childRouter._routerCanReuse(instruction.child);
|
||||
}
|
||||
});
|
||||
return this._outlet.routerCanReuse(instruction.component).then((result) => {
|
||||
instruction.component.reuse = result;
|
||||
if (result && isPresent(this._childRouter) && isPresent(instruction.child)) {
|
||||
return this._childRouter._routerCanReuse(instruction.child);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private _canActivate(nextInstruction: Instruction): Promise<boolean> {
|
||||
@ -474,47 +477,46 @@ export class RootRouter extends Router {
|
||||
/** @internal */
|
||||
_locationSub: Object;
|
||||
|
||||
constructor(registry: RouteRegistry, location: Location,
|
||||
@Inject(ROUTER_PRIMARY_COMPONENT) primaryComponent: Type) {
|
||||
constructor(
|
||||
registry: RouteRegistry, location: Location,
|
||||
@Inject(ROUTER_PRIMARY_COMPONENT) primaryComponent: Type) {
|
||||
super(registry, null, primaryComponent);
|
||||
this.root = this;
|
||||
this._location = location;
|
||||
this._locationSub = this._location.subscribe((change) => {
|
||||
// we call recognize ourselves
|
||||
this.recognize(change['url'])
|
||||
.then((instruction) => {
|
||||
if (isPresent(instruction)) {
|
||||
this.navigateByInstruction(instruction, isPresent(change['pop']))
|
||||
.then((_) => {
|
||||
// this is a popstate event; no need to change the URL
|
||||
if (isPresent(change['pop']) && change['type'] != 'hashchange') {
|
||||
return;
|
||||
}
|
||||
var emitPath = instruction.toUrlPath();
|
||||
var emitQuery = instruction.toUrlQuery();
|
||||
if (emitPath.length > 0 && emitPath[0] != '/') {
|
||||
emitPath = '/' + emitPath;
|
||||
}
|
||||
this.recognize(change['url']).then((instruction) => {
|
||||
if (isPresent(instruction)) {
|
||||
this.navigateByInstruction(instruction, isPresent(change['pop'])).then((_) => {
|
||||
// this is a popstate event; no need to change the URL
|
||||
if (isPresent(change['pop']) && change['type'] != 'hashchange') {
|
||||
return;
|
||||
}
|
||||
var emitPath = instruction.toUrlPath();
|
||||
var emitQuery = instruction.toUrlQuery();
|
||||
if (emitPath.length > 0 && emitPath[0] != '/') {
|
||||
emitPath = '/' + emitPath;
|
||||
}
|
||||
|
||||
// We've opted to use pushstate and popState APIs regardless of whether you
|
||||
// an app uses HashLocationStrategy or PathLocationStrategy.
|
||||
// However, apps that are migrating might have hash links that operate outside
|
||||
// angular to which routing must respond.
|
||||
// Therefore we know that all hashchange events occur outside Angular.
|
||||
// To support these cases where we respond to hashchanges and redirect as a
|
||||
// result, we need to replace the top item on the stack.
|
||||
if (change['type'] == 'hashchange') {
|
||||
if (instruction.toRootUrl() != this._location.path()) {
|
||||
this._location.replaceState(emitPath, emitQuery);
|
||||
}
|
||||
} else {
|
||||
this._location.go(emitPath, emitQuery);
|
||||
}
|
||||
});
|
||||
// We've opted to use pushstate and popState APIs regardless of whether you
|
||||
// an app uses HashLocationStrategy or PathLocationStrategy.
|
||||
// However, apps that are migrating might have hash links that operate outside
|
||||
// angular to which routing must respond.
|
||||
// Therefore we know that all hashchange events occur outside Angular.
|
||||
// To support these cases where we respond to hashchanges and redirect as a
|
||||
// result, we need to replace the top item on the stack.
|
||||
if (change['type'] == 'hashchange') {
|
||||
if (instruction.toRootUrl() != this._location.path()) {
|
||||
this._location.replaceState(emitPath, emitQuery);
|
||||
}
|
||||
} else {
|
||||
this._emitNavigationFail(change['url']);
|
||||
this._location.go(emitPath, emitQuery);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this._emitNavigationFail(change['url']);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
this.registry.configFromComponent(primaryComponent);
|
||||
@ -558,23 +560,23 @@ class ChildRouter extends Router {
|
||||
return this.parent.navigateByUrl(url, _skipLocationChange);
|
||||
}
|
||||
|
||||
navigateByInstruction(instruction: Instruction,
|
||||
_skipLocationChange: boolean = false): Promise<any> {
|
||||
navigateByInstruction(instruction: Instruction, _skipLocationChange: boolean = false):
|
||||
Promise<any> {
|
||||
// Delegate navigation to the root router
|
||||
return this.parent.navigateByInstruction(instruction, _skipLocationChange);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function canActivateOne(nextInstruction: Instruction,
|
||||
prevInstruction: Instruction): Promise<boolean> {
|
||||
function canActivateOne(
|
||||
nextInstruction: Instruction, prevInstruction: Instruction): Promise<boolean> {
|
||||
var next = _resolveToTrue;
|
||||
if (isBlank(nextInstruction.component)) {
|
||||
return next;
|
||||
}
|
||||
if (isPresent(nextInstruction.child)) {
|
||||
next = canActivateOne(nextInstruction.child,
|
||||
isPresent(prevInstruction) ? prevInstruction.child : null);
|
||||
next = canActivateOne(
|
||||
nextInstruction.child, isPresent(prevInstruction) ? prevInstruction.child : null);
|
||||
}
|
||||
return next.then<boolean>((result: boolean): boolean => {
|
||||
if (result == false) {
|
||||
@ -585,8 +587,8 @@ function canActivateOne(nextInstruction: Instruction,
|
||||
}
|
||||
var hook = getCanActivateHook(nextInstruction.component.componentType);
|
||||
if (isPresent(hook)) {
|
||||
return hook(nextInstruction.component,
|
||||
isPresent(prevInstruction) ? prevInstruction.component : null);
|
||||
return hook(
|
||||
nextInstruction.component, isPresent(prevInstruction) ? prevInstruction.component : null);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
@ -1,6 +1,8 @@
|
||||
import {ROUTER_PROVIDERS_COMMON} from './router_providers_common';
|
||||
import {BrowserPlatformLocation} from '@angular/platform-browser';
|
||||
import {PlatformLocation} from '@angular/common';
|
||||
import {BrowserPlatformLocation} from '@angular/platform-browser';
|
||||
|
||||
import {ROUTER_PROVIDERS_COMMON} from './router_providers_common';
|
||||
|
||||
|
||||
/**
|
||||
* A list of providers. To use the router, you must add this to your application.
|
||||
|
@ -1,18 +1,19 @@
|
||||
import {Location, LocationStrategy, PathLocationStrategy} from '@angular/common';
|
||||
import {ApplicationRef} from '@angular/core';
|
||||
import {LocationStrategy, PathLocationStrategy, Location} from '@angular/common';
|
||||
import {Router, RootRouter} from './router';
|
||||
import {RouteRegistry, ROUTER_PRIMARY_COMPONENT} from './route_registry';
|
||||
import {Type} from '../src/facade/lang';
|
||||
|
||||
import {BaseException} from '../src/facade/exceptions';
|
||||
import {Type} from '../src/facade/lang';
|
||||
|
||||
import {ROUTER_PRIMARY_COMPONENT, RouteRegistry} from './route_registry';
|
||||
import {RootRouter, Router} from './router';
|
||||
|
||||
|
||||
/**
|
||||
* The Platform agnostic ROUTER PROVIDERS
|
||||
*/
|
||||
export const ROUTER_PROVIDERS_COMMON: any[] = /*@ts2dart_const*/[
|
||||
RouteRegistry,
|
||||
/* @ts2dart_Provider */ {provide: LocationStrategy, useClass: PathLocationStrategy},
|
||||
Location,
|
||||
{
|
||||
/* @ts2dart_Provider */ {provide: LocationStrategy, useClass: PathLocationStrategy}, Location, {
|
||||
provide: Router,
|
||||
useFactory: routerFactory,
|
||||
deps: [RouteRegistry, Location, ROUTER_PRIMARY_COMPONENT, ApplicationRef]
|
||||
@ -24,8 +25,9 @@ export const ROUTER_PROVIDERS_COMMON: any[] = /*@ts2dart_const*/[
|
||||
}
|
||||
];
|
||||
|
||||
function routerFactory(registry: RouteRegistry, location: Location, primaryComponent: Type,
|
||||
appRef: ApplicationRef): RootRouter {
|
||||
function routerFactory(
|
||||
registry: RouteRegistry, location: Location, primaryComponent: Type,
|
||||
appRef: ApplicationRef): RootRouter {
|
||||
var rootRouter = new RootRouter(registry, location, primaryComponent);
|
||||
appRef.registerDisposeListener(() => rootRouter.dispose());
|
||||
return rootRouter;
|
||||
@ -33,7 +35,7 @@ function routerFactory(registry: RouteRegistry, location: Location, primaryCompo
|
||||
|
||||
function routerPrimaryComponentFactory(app: ApplicationRef): Type {
|
||||
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.');
|
||||
}
|
||||
return app.componentTypes[0];
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
import {isPresent, Type} from '../../facade/lang';
|
||||
import {Type, isPresent} from '../../facade/lang';
|
||||
import {BLANK_ROUTE_DATA, RouteData} from '../../instruction';
|
||||
|
||||
import {RouteHandler} from './route_handler';
|
||||
import {RouteData, BLANK_ROUTE_DATA} from '../../instruction';
|
||||
|
||||
|
||||
export class AsyncRouteHandler implements RouteHandler {
|
||||
|
@ -1,7 +1,8 @@
|
||||
import {PromiseWrapper} from '../../facade/async';
|
||||
import {isPresent, Type} from '../../facade/lang';
|
||||
import {Type, isPresent} from '../../facade/lang';
|
||||
import {BLANK_ROUTE_DATA, RouteData} from '../../instruction';
|
||||
|
||||
import {RouteHandler} from './route_handler';
|
||||
import {RouteData, BLANK_ROUTE_DATA} from '../../instruction';
|
||||
|
||||
|
||||
export class SyncRouteHandler implements RouteHandler {
|
||||
|
@ -1,9 +1,11 @@
|
||||
import {RegExpWrapper, StringWrapper, isPresent, isBlank} from '../../facade/lang';
|
||||
import {BaseException} from '../../facade/exceptions';
|
||||
import {StringMapWrapper} from '../../facade/collection';
|
||||
import {BaseException} from '../../facade/exceptions';
|
||||
import {RegExpWrapper, StringWrapper, isBlank, isPresent} from '../../facade/lang';
|
||||
import {RootUrl, Url, convertUrlParamsToArray} from '../../url_parser';
|
||||
import {TouchMap, normalizeString} from '../../utils';
|
||||
import {Url, RootUrl, convertUrlParamsToArray} from '../../url_parser';
|
||||
import {RoutePath, GeneratedUrl, MatchedUrl} from './route_path';
|
||||
|
||||
import {GeneratedUrl, MatchedUrl, RoutePath} from './route_path';
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@ -119,7 +121,8 @@ export class ParamRoutePath implements RoutePath {
|
||||
if (isPresent(currentUrlSegment)) {
|
||||
// the star segment consumes all of the remaining URL, including matrix params
|
||||
if (pathSegment instanceof StarPathSegment) {
|
||||
(positionalParams as any /** TODO #9100 */)[pathSegment.name] = currentUrlSegment.toString();
|
||||
(positionalParams as any /** TODO #9100 */)[pathSegment.name] =
|
||||
currentUrlSegment.toString();
|
||||
captured.push(currentUrlSegment.toString());
|
||||
nextUrlSegment = null;
|
||||
break;
|
||||
@ -128,7 +131,8 @@ export class ParamRoutePath implements RoutePath {
|
||||
captured.push(currentUrlSegment.path);
|
||||
|
||||
if (pathSegment instanceof DynamicPathSegment) {
|
||||
(positionalParams as any /** TODO #9100 */)[pathSegment.name] = decodeDynamicSegment(currentUrlSegment.path);
|
||||
(positionalParams as any /** TODO #9100 */)[pathSegment.name] =
|
||||
decodeDynamicSegment(currentUrlSegment.path);
|
||||
} else if (!pathSegment.match(currentUrlSegment.path)) {
|
||||
return null;
|
||||
}
|
||||
@ -190,7 +194,7 @@ export class ParamRoutePath implements RoutePath {
|
||||
private _parsePathString(routePath: string) {
|
||||
// normalize route as not starting with a "/". Recognition will
|
||||
// also normalize.
|
||||
if (routePath.startsWith("/")) {
|
||||
if (routePath.startsWith('/')) {
|
||||
routePath = routePath.substring(1);
|
||||
}
|
||||
|
||||
@ -230,7 +234,8 @@ export class ParamRoutePath implements RoutePath {
|
||||
// The code below uses place values to combine the different types of segments into a single
|
||||
// string that we can sort later. Each static segment is marked as a specificity of "2," each
|
||||
// dynamic segment is worth "1" specificity, and stars are worth "0" specificity.
|
||||
var i: any /** TODO #9100 */, length = this._segments.length, specificity: any /** TODO #9100 */;
|
||||
var i: any /** TODO #9100 */, length = this._segments.length,
|
||||
specificity: any /** TODO #9100 */;
|
||||
if (length == 0) {
|
||||
// a single slash (or "empty segment" is as specific as a static segment
|
||||
specificity += '2';
|
||||
|
@ -1,7 +1,9 @@
|
||||
import {RegExpWrapper, RegExpMatcherWrapper, isBlank} from '../../facade/lang';
|
||||
import {BaseException} from '@angular/core';
|
||||
|
||||
import {RegExpMatcherWrapper, RegExpWrapper, isBlank} from '../../facade/lang';
|
||||
import {Url} from '../../url_parser';
|
||||
import {RoutePath, GeneratedUrl, MatchedUrl} from './route_path';
|
||||
|
||||
import {GeneratedUrl, MatchedUrl, RoutePath} from './route_path';
|
||||
|
||||
|
||||
export interface RegexSerializer { (params: {[key: string]: any}): GeneratedUrl; }
|
||||
@ -10,7 +12,7 @@ function computeNumberOfRegexGroups(regex: string): number {
|
||||
// cleverly compute regex groups by appending an alternative empty matching
|
||||
// pattern and match against an empty string, the resulting match still
|
||||
// receives all the other groups
|
||||
var test_regex = RegExpWrapper.create(regex + "|");
|
||||
var test_regex = RegExpWrapper.create(regex + '|');
|
||||
var matcher = RegExpWrapper.matcher(test_regex, '');
|
||||
var match = RegExpMatcherWrapper.next(matcher);
|
||||
return match.length;
|
||||
@ -23,8 +25,9 @@ export class RegexRoutePath implements RoutePath {
|
||||
|
||||
private _regex: RegExp;
|
||||
|
||||
constructor(private _reString: string, private _serializer: RegexSerializer,
|
||||
private _groupNames?: Array<string>) {
|
||||
constructor(
|
||||
private _reString: string, private _serializer: RegexSerializer,
|
||||
private _groupNames?: Array<string>) {
|
||||
this.hash = this._reString;
|
||||
this._regex = RegExpWrapper.create(this._reString);
|
||||
if (this._groupNames != null) {
|
||||
|
@ -1,8 +1,9 @@
|
||||
import {Url} from '../../url_parser';
|
||||
|
||||
export class MatchedUrl {
|
||||
constructor(public urlPath: string, public urlParams: string[],
|
||||
public allParams: {[key: string]: any}, public auxiliary: Url[], public rest: Url) {}
|
||||
constructor(
|
||||
public urlPath: string, public urlParams: string[], public allParams: {[key: string]: any},
|
||||
public auxiliary: Url[], public rest: Url) {}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,22 +1,18 @@
|
||||
import {isBlank, isPresent, isFunction} from '../facade/lang';
|
||||
import {BaseException} from '../facade/exceptions';
|
||||
import {Map} from '../facade/collection';
|
||||
import {PromiseWrapper} from '../facade/async';
|
||||
import {AbstractRule, RouteRule, RedirectRule, RouteMatch, PathMatch} from './rules';
|
||||
import {
|
||||
Route,
|
||||
AsyncRoute,
|
||||
AuxRoute,
|
||||
Redirect,
|
||||
RouteDefinition
|
||||
} from '../route_config/route_config_impl';
|
||||
import {Map} from '../facade/collection';
|
||||
import {BaseException} from '../facade/exceptions';
|
||||
import {isBlank, isFunction, isPresent} from '../facade/lang';
|
||||
import {ComponentInstruction} from '../instruction';
|
||||
import {AsyncRoute, AuxRoute, Redirect, Route, RouteDefinition} from '../route_config/route_config_impl';
|
||||
import {Url} from '../url_parser';
|
||||
|
||||
import {AsyncRouteHandler} from './route_handlers/async_route_handler';
|
||||
import {SyncRouteHandler} from './route_handlers/sync_route_handler';
|
||||
import {RoutePath} from './route_paths/route_path';
|
||||
import {ParamRoutePath} from './route_paths/param_route_path';
|
||||
import {RegexRoutePath} from './route_paths/regex_route_path';
|
||||
import {Url} from '../url_parser';
|
||||
import {ComponentInstruction} from '../instruction';
|
||||
import {RoutePath} from './route_paths/route_path';
|
||||
import {AbstractRule, PathMatch, RedirectRule, RouteMatch, RouteRule} from './rules';
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@ -178,8 +174,8 @@ export class RuleSet {
|
||||
if (isPresent(config.path)) {
|
||||
// Auxiliary routes do not have a slash at the start
|
||||
let path = (config instanceof AuxRoute && config.path.startsWith('/')) ?
|
||||
config.path.substring(1) :
|
||||
config.path;
|
||||
config.path.substring(1) :
|
||||
config.path;
|
||||
return new ParamRoutePath(path);
|
||||
}
|
||||
throw new BaseException('Route must provide either a path or regex property');
|
||||
|
@ -1,19 +1,21 @@
|
||||
import {isPresent, isBlank} from '../facade/lang';
|
||||
import {BaseException} from '../facade/exceptions';
|
||||
import {PromiseWrapper} from '../facade/promise';
|
||||
import {Map} from '../facade/collection';
|
||||
import {RouteHandler} from './route_handlers/route_handler';
|
||||
import {Url, convertUrlParamsToArray} from '../url_parser';
|
||||
import {BaseException} from '../facade/exceptions';
|
||||
import {isBlank, isPresent} from '../facade/lang';
|
||||
import {PromiseWrapper} from '../facade/promise';
|
||||
import {ComponentInstruction} from '../instruction';
|
||||
import {RoutePath, GeneratedUrl} from './route_paths/route_path';
|
||||
import {Url, convertUrlParamsToArray} from '../url_parser';
|
||||
|
||||
import {RouteHandler} from './route_handlers/route_handler';
|
||||
import {GeneratedUrl, RoutePath} from './route_paths/route_path';
|
||||
|
||||
|
||||
|
||||
// RouteMatch objects hold information about a match between a rule and a URL
|
||||
export abstract class RouteMatch {}
|
||||
|
||||
export class PathMatch extends RouteMatch {
|
||||
constructor(public instruction: ComponentInstruction, public remaining: Url,
|
||||
public remainingAux: Url[]) {
|
||||
constructor(
|
||||
public instruction: ComponentInstruction, public remaining: Url, public remainingAux: Url[]) {
|
||||
super();
|
||||
}
|
||||
}
|
||||
@ -67,8 +69,8 @@ export class RouteRule implements AbstractRule {
|
||||
|
||||
// TODO: cache component instruction instances by params and by ParsedUrl instance
|
||||
|
||||
constructor(private _routePath: RoutePath, public handler: RouteHandler,
|
||||
private _routeName: string) {
|
||||
constructor(
|
||||
private _routePath: RoutePath, public handler: RouteHandler, private _routeName: string) {
|
||||
this.specificity = this._routePath.specificity;
|
||||
this.hash = this._routePath.hash;
|
||||
this.terminal = this._routePath.terminal;
|
||||
@ -100,8 +102,8 @@ export class RouteRule implements AbstractRule {
|
||||
return this._routePath.generateUrl(params);
|
||||
}
|
||||
|
||||
private _getInstruction(urlPath: string, urlParams: string[],
|
||||
params: {[key: string]: any}): ComponentInstruction {
|
||||
private _getInstruction(urlPath: string, urlParams: string[], params: {[key: string]: any}):
|
||||
ComponentInstruction {
|
||||
if (isBlank(this.handler.componentType)) {
|
||||
throw new BaseException(`Tried to get instruction before the type was loaded.`);
|
||||
}
|
||||
@ -109,9 +111,9 @@ export class RouteRule implements AbstractRule {
|
||||
if (this._cache.has(hashKey)) {
|
||||
return this._cache.get(hashKey);
|
||||
}
|
||||
var instruction =
|
||||
new ComponentInstruction(urlPath, urlParams, this.handler.data, this.handler.componentType,
|
||||
this.terminal, this.specificity, params, this._routeName);
|
||||
var instruction = new ComponentInstruction(
|
||||
urlPath, urlParams, this.handler.data, this.handler.componentType, this.terminal,
|
||||
this.specificity, params, this._routeName);
|
||||
this._cache.set(hashKey, instruction);
|
||||
|
||||
return instruction;
|
||||
|
@ -1,6 +1,6 @@
|
||||
import {StringMapWrapper} from '../src/facade/collection';
|
||||
import {isPresent, isBlank, RegExpWrapper} from '../src/facade/lang';
|
||||
import {BaseException} from '../src/facade/exceptions';
|
||||
import {RegExpWrapper, isBlank, isPresent} from '../src/facade/lang';
|
||||
|
||||
export function convertUrlParamsToArray(urlParams: {[key: string]: any}): string[] {
|
||||
var paramsArray: any[] /** TODO #9100 */ = [];
|
||||
@ -8,7 +8,9 @@ export function convertUrlParamsToArray(urlParams: {[key: string]: any}): string
|
||||
return [];
|
||||
}
|
||||
StringMapWrapper.forEach(
|
||||
urlParams, (value: any /** TODO #9100 */, key: any /** TODO #9100 */) => { paramsArray.push((value === true) ? key : key + '=' + value); });
|
||||
urlParams, (value: any /** TODO #9100 */, key: any /** TODO #9100 */) => {
|
||||
paramsArray.push((value === true) ? key : key + '=' + value);
|
||||
});
|
||||
return paramsArray;
|
||||
}
|
||||
|
||||
@ -21,9 +23,9 @@ export function serializeParams(urlParams: {[key: string]: any}, joiner = '&'):
|
||||
* This class represents a parsed URL
|
||||
*/
|
||||
export class Url {
|
||||
constructor(public path: string, public child: Url = null,
|
||||
public auxiliary: Url[] = /*@ts2dart_const*/[],
|
||||
public params: {[key: string]: any} = /*@ts2dart_const*/ {}) {}
|
||||
constructor(
|
||||
public path: string, public child: Url = null, public auxiliary: Url[] = /*@ts2dart_const*/[],
|
||||
public params: {[key: string]: any} = /*@ts2dart_const*/ {}) {}
|
||||
|
||||
toString(): string {
|
||||
return this.path + this._matrixParamsToString() + this._auxToString() + this._childString();
|
||||
@ -34,8 +36,8 @@ export class Url {
|
||||
/** @internal */
|
||||
_auxToString(): string {
|
||||
return this.auxiliary.length > 0 ?
|
||||
('(' + this.auxiliary.map(sibling => sibling.toString()).join('//') + ')') :
|
||||
'';
|
||||
('(' + this.auxiliary.map(sibling => sibling.toString()).join('//') + ')') :
|
||||
'';
|
||||
}
|
||||
|
||||
private _matrixParamsToString(): string {
|
||||
@ -51,8 +53,9 @@ export class Url {
|
||||
}
|
||||
|
||||
export class RootUrl extends Url {
|
||||
constructor(path: string, child: Url = null, auxiliary: Url[] = /*@ts2dart_const*/[],
|
||||
params: {[key: string]: any} = null) {
|
||||
constructor(
|
||||
path: string, child: Url = null, auxiliary: Url[] = /*@ts2dart_const*/[],
|
||||
params: {[key: string]: any} = null) {
|
||||
super(path, child, auxiliary, params);
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import {isPresent, isBlank} from '../src/facade/lang';
|
||||
import {StringMapWrapper} from '../src/facade/collection';
|
||||
import {isBlank, isPresent} from '../src/facade/lang';
|
||||
|
||||
export class TouchMap {
|
||||
map: {[key: string]: string} = {};
|
||||
|
Reference in New Issue
Block a user