66 List ,
77 ListWrapper
88} from 'angular2/src/facade/collection' ;
9- import { Promise , PromiseWrapper } from 'angular2/src/facade/async' ;
109import { isPresent , normalizeBlank } from 'angular2/src/facade/lang' ;
1110
1211export class RouteParams {
@@ -20,7 +19,7 @@ export class RouteParams {
2019 */
2120export class Instruction {
2221 component : any ;
23- private _children : StringMap < string , Instruction > ;
22+ child : Instruction ;
2423
2524 // the part of the URL captured by this instruction
2625 capturedUrl : string ;
@@ -32,86 +31,47 @@ export class Instruction {
3231 reuse : boolean ;
3332 specificity : number ;
3433
35- constructor ( { params, component, children , matchedUrl, parentSpecificity} : {
34+ constructor ( { params, component, child , matchedUrl, parentSpecificity} : {
3635 params ?: StringMap < string , any > ,
3736 component ?: any ,
38- children ?: StringMap < string , Instruction > ,
37+ child ?: Instruction ,
3938 matchedUrl ?: string ,
4039 parentSpecificity ?: number
4140 } = { } ) {
4241 this . reuse = false ;
4342 this . capturedUrl = matchedUrl ;
4443 this . accumulatedUrl = matchedUrl ;
4544 this . specificity = parentSpecificity ;
46- if ( isPresent ( children ) ) {
47- this . _children = children ;
48- var childUrl ;
49- StringMapWrapper . forEach ( this . _children , ( child , _ ) => {
50- childUrl = child . accumulatedUrl ;
51- this . specificity += child . specificity ;
52- } ) ;
45+ if ( isPresent ( child ) ) {
46+ this . child = child ;
47+ this . specificity += child . specificity ;
48+ var childUrl = child . accumulatedUrl ;
5349 if ( isPresent ( childUrl ) ) {
5450 this . accumulatedUrl += childUrl ;
5551 }
5652 } else {
57- this . _children = StringMapWrapper . create ( ) ;
53+ this . child = null ;
5854 }
5955 this . component = component ;
6056 this . params = params ;
6157 }
6258
63- hasChild ( outletName : string ) : boolean {
64- return StringMapWrapper . contains ( this . _children , outletName ) ;
65- }
66-
67- /**
68- * Returns the child instruction with the given outlet name
69- */
70- getChild ( outletName : string ) : Instruction {
71- return StringMapWrapper . get ( this . _children , outletName ) ;
72- }
73-
74- /**
75- * (child:Instruction, outletName:string) => {}
76- */
77- forEachChild ( fn : Function ) : void { StringMapWrapper . forEach ( this . _children , fn ) ; }
78-
79- /**
80- * Does a synchronous, breadth-first traversal of the graph of instructions.
81- * Takes a function with signature:
82- * (child:Instruction, outletName:string) => {}
83- */
84- traverseSync ( fn : Function ) : void {
85- this . forEachChild ( fn ) ;
86- this . forEachChild ( ( childInstruction , _ ) => childInstruction . traverseSync ( fn ) ) ;
87- }
88-
59+ hasChild ( ) : boolean { return isPresent ( this . child ) ; }
8960
9061 /**
9162 * Takes a currently active instruction and sets a reuse flag on each of this instruction's
9263 * children
9364 */
9465 reuseComponentsFrom ( oldInstruction : Instruction ) : void {
95- this . traverseSync ( ( childInstruction , outletName ) => {
96- var oldInstructionChild = oldInstruction . getChild ( outletName ) ;
97- if ( shouldReuseComponent ( childInstruction , oldInstructionChild ) ) {
98- childInstruction . reuse = true ;
99- }
100- } ) ;
66+ var nextInstruction = this ;
67+ while ( nextInstruction . reuse = shouldReuseComponent ( nextInstruction , oldInstruction ) &&
68+ isPresent ( oldInstruction = oldInstruction . child ) &&
69+ isPresent ( nextInstruction = nextInstruction . child ) )
70+ ;
10171 }
10272}
10373
10474function shouldReuseComponent ( instr1 : Instruction , instr2 : Instruction ) : boolean {
10575 return instr1 . component == instr2 . component &&
10676 StringMapWrapper . equals ( instr1 . params , instr2 . params ) ;
10777}
108-
109- function mapObjAsync ( obj : StringMap < string , any > , fn ) : Promise < List < any > > {
110- return PromiseWrapper . all ( mapObj ( obj , fn ) ) ;
111- }
112-
113- function mapObj ( obj : StringMap < any , any > , fn : Function ) : List < any > {
114- var result = ListWrapper . create ( ) ;
115- StringMapWrapper . forEach ( obj , ( value , key ) => ListWrapper . push ( result , fn ( value , key ) ) ) ;
116- return result ;
117- }
0 commit comments