chore(typing): extract abstract superclasses to replace @private constructors
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
import {Map, MapWrapper, StringMapWrapper, ListWrapper} from 'angular2/src/core/facade/collection';
|
||||
import {unimplemented} from 'angular2/src/core/facade/exceptions';
|
||||
import {isPresent, isBlank, normalizeBlank, Type} from 'angular2/src/core/facade/lang';
|
||||
import {Promise} from 'angular2/src/core/facade/async';
|
||||
|
||||
@ -140,42 +141,55 @@ function stringifyAux(instruction: Instruction): string {
|
||||
*
|
||||
* You should not modify this object. It should be treated as immutable.
|
||||
*/
|
||||
export class ComponentInstruction {
|
||||
export abstract class ComponentInstruction {
|
||||
reuse: boolean = false;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
constructor(public urlPath: string, public urlParams: string[],
|
||||
private _recognizer: PathRecognizer, public params: {[key: string]: any} = null) {}
|
||||
public urlPath: string;
|
||||
public urlParams: string[];
|
||||
public params: {[key: string]: any};
|
||||
|
||||
/**
|
||||
* Returns the component type of the represented route, or `null` if this instruction
|
||||
* hasn't been resolved.
|
||||
*/
|
||||
get componentType() { return this._recognizer.handler.componentType; }
|
||||
get componentType() { return unimplemented(); };
|
||||
|
||||
/**
|
||||
* Returns a promise that will resolve to component type of the represented route.
|
||||
* If this instruction references an {@link AsyncRoute}, the `loader` function of that route
|
||||
* will run.
|
||||
*/
|
||||
resolveComponentType(): Promise<Type> { return this._recognizer.handler.resolveComponentType(); }
|
||||
abstract resolveComponentType(): Promise<Type>;
|
||||
|
||||
/**
|
||||
* Returns the specificity of the route associated with this `Instruction`.
|
||||
*/
|
||||
get specificity() { return this._recognizer.specificity; }
|
||||
get specificity() { return unimplemented(); };
|
||||
|
||||
/**
|
||||
* Returns `true` if the component type of this instruction has no child {@link RouteConfig},
|
||||
* or `false` if it does.
|
||||
*/
|
||||
get terminal() { return this._recognizer.terminal; }
|
||||
get terminal() { return unimplemented(); };
|
||||
|
||||
/**
|
||||
* Returns the route data of the given route that was specified in the {@link RouteDefinition},
|
||||
* or `null` if no route data was specified.
|
||||
*/
|
||||
abstract routeData(): Object;
|
||||
}
|
||||
|
||||
export class ComponentInstruction_ extends ComponentInstruction {
|
||||
constructor(urlPath: string, urlParams: string[], private _recognizer: PathRecognizer,
|
||||
params: {[key: string]: any} = null) {
|
||||
super();
|
||||
this.urlPath = urlPath;
|
||||
this.urlParams = urlParams;
|
||||
this.params = params;
|
||||
}
|
||||
|
||||
get componentType() { return this._recognizer.handler.componentType; }
|
||||
resolveComponentType(): Promise<Type> { return this._recognizer.handler.resolveComponentType(); }
|
||||
get specificity() { return this._recognizer.specificity; }
|
||||
get terminal() { return this._recognizer.terminal; }
|
||||
routeData(): Object { return this._recognizer.handler.data; }
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import {Map, MapWrapper, StringMapWrapper} from 'angular2/src/core/facade/collec
|
||||
import {RouteHandler} from './route_handler';
|
||||
import {Url, RootUrl, serializeParams} from './url_parser';
|
||||
import {ComponentInstruction} from './instruction';
|
||||
import {ComponentInstruction_} from "./instruction";
|
||||
|
||||
class TouchMap {
|
||||
map: {[key: string]: string} = {};
|
||||
@ -297,7 +298,7 @@ export class PathRecognizer {
|
||||
if (this._cache.has(hashKey)) {
|
||||
return this._cache.get(hashKey);
|
||||
}
|
||||
var instruction = new ComponentInstruction(urlPath, urlParams, _recognizer, params);
|
||||
var instruction = new ComponentInstruction_(urlPath, urlParams, _recognizer, params);
|
||||
this._cache.set(hashKey, instruction);
|
||||
|
||||
return instruction;
|
||||
|
@ -12,6 +12,7 @@ import {ComponentInstruction, RouteParams} from './instruction';
|
||||
import {ROUTE_DATA} from './route_data';
|
||||
import * as hookMod from './lifecycle_annotations';
|
||||
import {hasLifecycleHook} from './route_lifecycle_reflector';
|
||||
import {Type} from "../core/facade/lang";
|
||||
|
||||
let _resolveToTrue = PromiseWrapper.resolve(true);
|
||||
|
||||
@ -24,18 +25,59 @@ let _resolveToTrue = PromiseWrapper.resolve(true);
|
||||
* <router-outlet></router-outlet>
|
||||
* ```
|
||||
*/
|
||||
@Directive({selector: 'router-outlet'})
|
||||
export class RouterOutlet {
|
||||
export abstract class RouterOutlet {
|
||||
name: string = null;
|
||||
|
||||
/**
|
||||
* Called by the Router to instantiate a new component during the commit phase of a navigation.
|
||||
* This method in turn is responsible for calling the `onActivate` hook of its child.
|
||||
*/
|
||||
abstract activate(nextInstruction: ComponentInstruction): Promise<any>;
|
||||
|
||||
/**
|
||||
* Called by the {@link Router} during the commit phase of a navigation when an outlet
|
||||
* reuses a component between different routes.
|
||||
* This method in turn is responsible for calling the `onReuse` hook of its child.
|
||||
*/
|
||||
abstract reuse(nextInstruction: ComponentInstruction): Promise<any>;
|
||||
|
||||
/**
|
||||
* Called by the {@link Router} when an outlet reuses a component across navigations.
|
||||
* This method in turn is responsible for calling the `onReuse` hook of its child.
|
||||
*/
|
||||
abstract deactivate(nextInstruction: ComponentInstruction): Promise<any>;
|
||||
|
||||
/**
|
||||
* Called by the {@link Router} during recognition phase of a navigation.
|
||||
*
|
||||
* If this resolves to `false`, the given navigation is cancelled.
|
||||
*
|
||||
* This method delegates to the child component's `canDeactivate` hook if it exists,
|
||||
* and otherwise resolves to true.
|
||||
*/
|
||||
abstract canDeactivate(nextInstruction: ComponentInstruction): Promise<boolean>;
|
||||
|
||||
/**
|
||||
* Called by the {@link Router} during recognition phase of a navigation.
|
||||
*
|
||||
* If the new child component has a different Type than the existing child component,
|
||||
* this will resolve to `false`. You can't reuse an old component when the new component
|
||||
* is of a different Type.
|
||||
*
|
||||
* Otherwise, this method delegates to the child component's `canReuse` hook if it exists,
|
||||
* or resolves to true if the hook is not present.
|
||||
*/
|
||||
abstract canReuse(nextInstruction: ComponentInstruction): Promise<boolean>;
|
||||
}
|
||||
|
||||
@Directive({selector: 'router-outlet'})
|
||||
export class RouterOutlet_ extends RouterOutlet {
|
||||
private _componentRef: ComponentRef = null;
|
||||
private _currentInstruction: ComponentInstruction = null;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
constructor(private _elementRef: ElementRef, private _loader: DynamicComponentLoader,
|
||||
private _parentRouter: routerMod.Router, @Attribute('name') nameAttr: string) {
|
||||
super();
|
||||
if (isPresent(nameAttr)) {
|
||||
this.name = nameAttr;
|
||||
this._parentRouter.registerAuxOutlet(this);
|
||||
@ -44,10 +86,6 @@ export class RouterOutlet {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the Router to instantiate a new component during the commit phase of a navigation.
|
||||
* This method in turn is responsible for calling the `onActivate` hook of its child.
|
||||
*/
|
||||
activate(nextInstruction: ComponentInstruction): Promise<any> {
|
||||
var previousInstruction = this._currentInstruction;
|
||||
this._currentInstruction = nextInstruction;
|
||||
@ -69,11 +107,6 @@ export class RouterOutlet {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the {@link Router} during the commit phase of a navigation when an outlet
|
||||
* reuses a component between different routes.
|
||||
* This method in turn is responsible for calling the `onReuse` hook of its child.
|
||||
*/
|
||||
reuse(nextInstruction: ComponentInstruction): Promise<any> {
|
||||
var previousInstruction = this._currentInstruction;
|
||||
this._currentInstruction = nextInstruction;
|
||||
@ -87,10 +120,6 @@ export class RouterOutlet {
|
||||
true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the {@link Router} when an outlet reuses a component across navigations.
|
||||
* This method in turn is responsible for calling the `onReuse` hook of its child.
|
||||
*/
|
||||
deactivate(nextInstruction: ComponentInstruction): Promise<any> {
|
||||
var next = _resolveToTrue;
|
||||
if (isPresent(this._componentRef) && isPresent(this._currentInstruction) &&
|
||||
@ -106,14 +135,6 @@ export class RouterOutlet {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the {@link Router} during recognition phase of a navigation.
|
||||
*
|
||||
* If this resolves to `false`, the given navigation is cancelled.
|
||||
*
|
||||
* This method delegates to the child component's `canDeactivate` hook if it exists,
|
||||
* and otherwise resolves to true.
|
||||
*/
|
||||
canDeactivate(nextInstruction: ComponentInstruction): Promise<boolean> {
|
||||
if (isBlank(this._currentInstruction)) {
|
||||
return _resolveToTrue;
|
||||
@ -125,16 +146,6 @@ export class RouterOutlet {
|
||||
return _resolveToTrue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the {@link Router} during recognition phase of a navigation.
|
||||
*
|
||||
* If the new child component has a different Type than the existing child component,
|
||||
* this will resolve to `false`. You can't reuse an old component when the new component
|
||||
* is of a different Type.
|
||||
*
|
||||
* Otherwise, this method delegates to the child component's `canReuse` hook if it exists,
|
||||
* or resolves to true if the hook is not present.
|
||||
*/
|
||||
canReuse(nextInstruction: ComponentInstruction): Promise<boolean> {
|
||||
var result;
|
||||
|
||||
|
Reference in New Issue
Block a user