6
6
List ,
7
7
ListWrapper
8
8
} from 'angular2/src/facade/collection' ;
9
- import { Promise , PromiseWrapper } from 'angular2/src/facade/async' ;
10
9
import { isPresent , normalizeBlank } from 'angular2/src/facade/lang' ;
11
10
12
11
export class RouteParams {
@@ -20,7 +19,7 @@ export class RouteParams {
20
19
*/
21
20
export class Instruction {
22
21
component : any ;
23
- private _children : StringMap < string , Instruction > ;
22
+ child : Instruction ;
24
23
25
24
// the part of the URL captured by this instruction
26
25
capturedUrl : string ;
@@ -32,86 +31,47 @@ export class Instruction {
32
31
reuse : boolean ;
33
32
specificity : number ;
34
33
35
- constructor ( { params, component, children , matchedUrl, parentSpecificity} : {
34
+ constructor ( { params, component, child , matchedUrl, parentSpecificity} : {
36
35
params ?: StringMap < string , any > ,
37
36
component ?: any ,
38
- children ?: StringMap < string , Instruction > ,
37
+ child ?: Instruction ,
39
38
matchedUrl ?: string ,
40
39
parentSpecificity ?: number
41
40
} = { } ) {
42
41
this . reuse = false ;
43
42
this . capturedUrl = matchedUrl ;
44
43
this . accumulatedUrl = matchedUrl ;
45
44
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 ;
53
49
if ( isPresent ( childUrl ) ) {
54
50
this . accumulatedUrl += childUrl ;
55
51
}
56
52
} else {
57
- this . _children = StringMapWrapper . create ( ) ;
53
+ this . child = null ;
58
54
}
59
55
this . component = component ;
60
56
this . params = params ;
61
57
}
62
58
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 ) ; }
89
60
90
61
/**
91
62
* Takes a currently active instruction and sets a reuse flag on each of this instruction's
92
63
* children
93
64
*/
94
65
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
+ ;
101
71
}
102
72
}
103
73
104
74
function shouldReuseComponent ( instr1 : Instruction , instr2 : Instruction ) : boolean {
105
75
return instr1 . component == instr2 . component &&
106
76
StringMapWrapper . equals ( instr1 . params , instr2 . params ) ;
107
77
}
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