2015-05-29 14:58:41 -07:00
|
|
|
import {
|
|
|
|
Map,
|
|
|
|
MapWrapper,
|
|
|
|
StringMap,
|
|
|
|
StringMapWrapper,
|
|
|
|
List,
|
|
|
|
ListWrapper
|
|
|
|
} from 'angular2/src/facade/collection';
|
2015-06-30 13:18:51 -07:00
|
|
|
import {isPresent, isBlank, normalizeBlank} from 'angular2/src/facade/lang';
|
|
|
|
|
|
|
|
import {PathRecognizer} from './path_recognizer';
|
2015-04-17 09:59:56 -07:00
|
|
|
|
|
|
|
export class RouteParams {
|
2015-05-29 14:58:41 -07:00
|
|
|
constructor(public params: StringMap<string, string>) {}
|
2015-05-14 15:24:35 +02:00
|
|
|
|
2015-05-29 14:58:41 -07:00
|
|
|
get(param: string): string { return normalizeBlank(StringMapWrapper.get(this.params, param)); }
|
2015-04-17 09:59:56 -07:00
|
|
|
}
|
|
|
|
|
2015-06-30 13:18:51 -07:00
|
|
|
|
2015-05-15 02:05:57 -07:00
|
|
|
/**
|
|
|
|
* An `Instruction` represents the component hierarchy of the application based on a given route
|
|
|
|
*/
|
2015-04-17 09:59:56 -07:00
|
|
|
export class Instruction {
|
2015-06-30 13:18:51 -07:00
|
|
|
// "capturedUrl" is the part of the URL captured by this instruction
|
|
|
|
// "accumulatedUrl" is the part of the URL captured by this instruction and all children
|
2015-05-29 14:58:41 -07:00
|
|
|
accumulatedUrl: string;
|
2015-06-30 13:18:51 -07:00
|
|
|
reuse: boolean = false;
|
2015-05-29 14:58:41 -07:00
|
|
|
specificity: number;
|
|
|
|
|
2015-06-30 13:18:51 -07:00
|
|
|
constructor(public component: any, public capturedUrl: string,
|
2015-07-21 01:26:43 -07:00
|
|
|
private _recognizer: PathRecognizer, public child: Instruction = null,
|
|
|
|
private _params: StringMap<string, any> = null) {
|
2015-06-30 13:18:51 -07:00
|
|
|
this.accumulatedUrl = capturedUrl;
|
|
|
|
this.specificity = _recognizer.specificity;
|
2015-05-21 13:59:14 -07:00
|
|
|
if (isPresent(child)) {
|
|
|
|
this.child = child;
|
|
|
|
this.specificity += child.specificity;
|
|
|
|
var childUrl = child.accumulatedUrl;
|
2015-04-17 09:59:56 -07:00
|
|
|
if (isPresent(childUrl)) {
|
2015-05-14 13:01:48 -07:00
|
|
|
this.accumulatedUrl += childUrl;
|
2015-04-17 09:59:56 -07:00
|
|
|
}
|
|
|
|
}
|
2015-06-30 13:18:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
params(): StringMap<string, string> {
|
|
|
|
if (isBlank(this._params)) {
|
|
|
|
this._params = this._recognizer.parseParams(this.capturedUrl);
|
|
|
|
}
|
|
|
|
return this._params;
|
2015-04-17 09:59:56 -07:00
|
|
|
}
|
|
|
|
}
|