@@ -98,7 +98,7 @@ define([
9898 var templateName = template . parameterName ;
9999 template = template . rawValue ;
100100 if ( value ) {
101- value = value . rawValue ;
101+ value = value . rawValue ;
102102 }
103103
104104 template = blocks . $unwrap ( template ) ;
@@ -120,7 +120,8 @@ define([
120120 if ( ! this . _el ) {
121121 var element = document . createElement ( 'div' ) ;
122122 element . innerHTML = html ;
123- this . _children = createVirtual ( element . childNodes [ 0 ] , this ) ;
123+ var children = createVirtual ( element . childNodes [ 0 ] , this ) ;
124+ this . _setChildren ( children ) ;
124125 this . _innerHTML = null ;
125126 } else {
126127 this . html ( html ) ;
@@ -264,9 +265,9 @@ define([
264265 supportsComments : true ,
265266
266267 _getStaticHtml : function ( domQuery , element ) {
267- var children = element . _children ;
268- var headers = element . _headers ;
269- var footers = element . _footers ;
268+ var children = element . _state && element . _state . template || element . _template || element . _children ;
269+ var headers = element . _state && element . _state . headers || element . _headers ;
270+ var footers = element . _state && element . _state . footer || element . _footers ;
270271 var index = - 1 ;
271272 var headerHtml = '' ;
272273 var footerHtml = '' ;
@@ -286,8 +287,13 @@ define([
286287 }
287288 }
288289 } else {
289- headers = element . _headers = [ ] ;
290- footers = element . _footers = [ ] ;
290+ if ( element . _state ) {
291+ headers = element . _state . headers = [ ] ;
292+ footers = element . _state . footers = [ ] ;
293+ } else {
294+ headers = element . _headers = [ ] ;
295+ footers = element . _footers = [ ] ;
296+ }
291297
292298 while ( ++ index < children . length ) {
293299 child = children [ index ] ;
@@ -331,14 +337,14 @@ define([
331337 var staticHtml ;
332338 var html ;
333339
334- if ( this . _sync ) {
340+ if ( element . _sync ) {
335341 element . updateChildren ( collection , collection . length , domQuery , this . _el ) ;
336342 return ;
337343 }
338344
339- this . _template = this . _template || this . _children ;
345+ element . _template = element . _template || element . _children ;
340346
341- this . _childrenEach = true ;
347+ element . _childrenEach = true ;
342348
343349 if ( domQuery . _serverData ) {
344350 elementData = domQuery . _serverData [ ElementsData . id ( this ) ] ;
@@ -347,9 +353,14 @@ define([
347353 var div = document . createElement ( 'div' ) ;
348354 div . innerHTML = elementData ;
349355 element . _template = element . _children = createVirtual ( div . childNodes [ 0 ] , element ) ;
356+ if ( element . _state ) {
357+ element . _state . template = blocks . clone ( element . _template , true ) ;
358+ }
350359 }
351360 }
352361
362+
363+
353364 staticHtml = queries . each . _getStaticHtml ( domQuery , element ) ;
354365 html = staticHtml . header ;
355366
@@ -435,10 +446,13 @@ define([
435446 var value = Expression . Create ( '{{' + ( options . value || $thisStr ) + '}}' , 'value' ) ;
436447 var caption = blocks . isString ( options . caption ) && new VirtualElement ( 'option' ) ;
437448 var option = new VirtualElement ( 'option' ) ;
438- var children = this . _children ;
449+ var children = this . _state && this . _state . template || this . _template || this . _children ;
439450 var i = 0 ;
440451 var child ;
441-
452+ if ( this . _sync ) {
453+ blocks . queries . each . preprocess . call ( this , domQuery , collection ) ;
454+ return ;
455+ }
442456 for ( ; i < children . length ; i ++ ) {
443457 child = children [ i ] ;
444458 if ( ! child . _attributes || ( child . _attributes && ! child . _attributes [ 'data-role' ] ) ) {
@@ -449,22 +463,24 @@ define([
449463 option . _attributeExpressions . push ( value ) ;
450464 option . _children . push ( text ) ;
451465 option . _parent = this ;
452- this . _children . push ( option ) ;
466+ children . push ( option ) ;
453467
454468 if ( caption ) {
455469 caption . _attributes [ 'data-role' ] = 'header' ;
456470 caption . _innerHTML = options . caption ;
457- this . addChild ( caption ) ;
471+ caption . _parent = this ;
472+ children . push ( caption ) ;
458473 }
459474 blocks . queries . each . preprocess . call ( this , domQuery , collection ) ;
460475 } ,
461476
462477 update : function ( domQuery , collection ) {
463478 var elementData = ElementsData . data ( this ) ;
464479 var rawCollection = collection ( ) ;
465- var headers = elementData . virtual . _headers ;
480+ var state = elementData . virtual . _state ;
481+ var headers = state && state . headers || elementData . virtual . _headers ;
466482 var valueObservable = elementData . valueObservable ;
467- var valueExpression = elementData . virtual . _template [ 0 ] . _attributeExpressions [ 0 ] ;
483+ var valueExpression = ( state && state . template [ 0 ] || elementData . virtual . _template [ 0 ] ) . _attributeExpressions [ 0 ] ;
468484 var rawValue = blocks . isObservable ( valueObservable ) ? valueObservable . _getValue ( ) : this . value ;
469485 var expression ;
470486 var value ;
0 commit comments