@@ -23,14 +23,15 @@ export class View {
2323 /// to keep track of the nodes.
2424 @FIELD ( 'final nodes:List<Node>' )
2525 @FIELD ( 'final onChangeDispatcher:OnChangeDispatcher' )
26- constructor ( fragment :DocumentFragment , elementInjector :List , rootElementInjectors :List , textNodes :List ) {
26+ constructor ( fragment :DocumentFragment , elementInjector :List ,
27+ rootElementInjectors :List , textNodes :List , bindElements :List ) {
2728 this . fragment = fragment ;
2829 this . nodes = ListWrapper . clone ( fragment . childNodes ) ;
2930 this . elementInjectors = elementInjector ;
3031 this . rootElementInjectors = rootElementInjectors ;
3132 this . onChangeDispatcher = null ;
3233 this . textNodes = textNodes ;
33- this . bindElements = null ;
34+ this . bindElements = bindElements ;
3435 }
3536
3637 onRecordChange ( record :Record , target ) {
@@ -39,7 +40,7 @@ export class View {
3940 // we know that it is DirectivePropertyMemento
4041 var directiveMemento :DirectivePropertyMemento = target ;
4142 directiveMemento . invoke ( record , this . elementInjectors ) ;
42- } else if ( target instanceof ElementPropertyMemento ) {
43+ } else if ( target instanceof ElementPropertyMemento ) {
4344 var elementMemento :ElementPropertyMemento = target ;
4445 elementMemento . invoke ( record , this . bindElements ) ;
4546 } else {
@@ -83,16 +84,22 @@ export class ProtoView {
8384 var elementInjectors = ProtoView . _createElementInjectors ( elements , protos ) ;
8485 var rootElementInjectors = ProtoView . _rootElementInjectors ( elementInjectors ) ;
8586 var textNodes = ProtoView . _textNodes ( elements , protos ) ;
87+ var bindElements = ProtoView . _bindElements ( elements , protos ) ;
8688
87- return new View ( fragment , elementInjectors , rootElementInjectors , textNodes ) ;
89+ return new View ( fragment , elementInjectors , rootElementInjectors , textNodes ,
90+ bindElements ) ;
8891 }
8992
9093 static _createElementInjectors ( elements , protos ) {
9194 var injectors = ListWrapper . createFixedSize ( protos . length ) ;
9295 for ( var i = 0 ; i < protos . length ; ++ i ) {
9396 injectors [ i ] = ProtoView . _createElementInjector ( elements [ i ] , protos [ i ] ) ;
9497 }
95- ListWrapper . forEach ( protos , p => p . clearElementInjector ( ) ) ;
98+ // Cannot be rolled into loop above, because parentInjector pointers need
99+ // to be set on the children.
100+ for ( var i = 0 ; i < protos . length ; ++ i ) {
101+ protos [ i ] . clearElementInjector ( ) ;
102+ }
96103 return injectors ;
97104 }
98105
@@ -108,16 +115,26 @@ export class ProtoView {
108115 static _textNodes ( elements , protos ) {
109116 var textNodes = [ ] ;
110117 for ( var i = 0 ; i < protos . length ; ++ i ) {
111- ProtoView . _collectTextNodes ( textNodes , elements [ i ] , protos [ i ] ) ;
118+ ProtoView . _collectTextNodes ( textNodes , elements [ i ] ,
119+ protos [ i ] . textNodeIndices ) ;
112120 }
113121 return textNodes ;
114122 }
115123
116- static _collectTextNodes ( allTextNodes , element , proto ) {
124+ static _bindElements ( elements , protos ) :List < Element > {
125+ var bindElements = [ ] ;
126+ for ( var i = 0 ; i < protos . length ; ++ i ) {
127+ if ( protos [ i ] . hasElementPropertyBindings ) ListWrapper . push (
128+ bindElements , elements [ i ] ) ;
129+ }
130+ return bindElements ;
131+ }
132+
133+ static _collectTextNodes ( allTextNodes , element , indices ) {
117134 var childNodes = DOM . childNodes ( element ) ;
118- ListWrapper . forEach ( proto . textNodes , ( i ) => {
119- ListWrapper . push ( allTextNodes , childNodes [ i ] ) ;
120- } ) ;
135+ for ( var i = 0 ; i < indices . length ; ++ i ) {
136+ ListWrapper . push ( allTextNodes , childNodes [ indices [ i ] ] ) ;
137+ }
121138 }
122139}
123140
@@ -129,23 +146,22 @@ export class ElementPropertyMemento {
129146 this . _propertyName = propertyName ;
130147 }
131148
132- invoke ( record :Record , elementInjectors :List < Element > ) {
133- var element :Element = elementInjectors [ this . _elementIndex ] ;
149+ invoke ( record :Record , bindElements :List < Element > ) {
150+ var element :Element = bindElements [ this . _elementIndex ] ;
134151 DOM . setProperty ( element , this . _propertyName , record . currentValue ) ;
135152 }
136153}
137154
138155export class DirectivePropertyMemento {
139156 @FIELD ( 'final _elementInjectorIndex:int' )
140157 @FIELD ( 'final _directiveIndex:int' )
141- @FIELD ( 'final _setterName:String ' )
158+ @FIELD ( 'final _setterName:string ' )
142159 @FIELD ( 'final _setter:SetterFn' )
143160 constructor (
144161 elementInjectorIndex :number ,
145162 directiveIndex :number ,
146- setterName :String ,
147- setter :SetterFn )
148- {
163+ setterName :string ,
164+ setter :SetterFn ) {
149165 this . _elementInjectorIndex = elementInjectorIndex ;
150166 this . _directiveIndex = directiveIndex ;
151167 this . _setterName = setterName ;
@@ -154,7 +170,7 @@ export class DirectivePropertyMemento {
154170
155171 invoke ( record :Record , elementInjectors :List < ElementInjector > ) {
156172 var elementInjector :ElementInjector = elementInjectors [ this . _elementInjectorIndex ] ;
157- var directive = elementInjectors [ this . _directiveIndex ] ;
173+ var directive = elementInjector . getAtIndex ( this . _directiveIndex ) ;
158174 this . _setter ( directive , record . currentValue ) ;
159175 }
160176}
0 commit comments