@@ -98,7 +98,7 @@ define([
98
98
var templateName = template . parameterName ;
99
99
template = template . rawValue ;
100
100
if ( value ) {
101
- value = value . rawValue ;
101
+ value = value . rawValue ;
102
102
}
103
103
104
104
template = blocks . $unwrap ( template ) ;
@@ -120,7 +120,8 @@ define([
120
120
if ( ! this . _el ) {
121
121
var element = document . createElement ( 'div' ) ;
122
122
element . innerHTML = html ;
123
- this . _children = createVirtual ( element . childNodes [ 0 ] , this ) ;
123
+ var children = createVirtual ( element . childNodes [ 0 ] , this ) ;
124
+ this . _setChildren ( children ) ;
124
125
this . _innerHTML = null ;
125
126
} else {
126
127
this . html ( html ) ;
@@ -264,9 +265,9 @@ define([
264
265
supportsComments : true ,
265
266
266
267
_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 ;
270
271
var index = - 1 ;
271
272
var headerHtml = '' ;
272
273
var footerHtml = '' ;
@@ -286,8 +287,13 @@ define([
286
287
}
287
288
}
288
289
} 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
+ }
291
297
292
298
while ( ++ index < children . length ) {
293
299
child = children [ index ] ;
@@ -331,14 +337,14 @@ define([
331
337
var staticHtml ;
332
338
var html ;
333
339
334
- if ( this . _sync ) {
340
+ if ( element . _sync ) {
335
341
element . updateChildren ( collection , collection . length , domQuery , this . _el ) ;
336
342
return ;
337
343
}
338
344
339
- this . _template = this . _template || this . _children ;
345
+ element . _template = element . _template || element . _children ;
340
346
341
- this . _childrenEach = true ;
347
+ element . _childrenEach = true ;
342
348
343
349
if ( domQuery . _serverData ) {
344
350
elementData = domQuery . _serverData [ ElementsData . id ( this ) ] ;
@@ -347,9 +353,14 @@ define([
347
353
var div = document . createElement ( 'div' ) ;
348
354
div . innerHTML = elementData ;
349
355
element . _template = element . _children = createVirtual ( div . childNodes [ 0 ] , element ) ;
356
+ if ( element . _state ) {
357
+ element . _state . template = blocks . clone ( element . _template , true ) ;
358
+ }
350
359
}
351
360
}
352
361
362
+
363
+
353
364
staticHtml = queries . each . _getStaticHtml ( domQuery , element ) ;
354
365
html = staticHtml . header ;
355
366
@@ -435,10 +446,13 @@ define([
435
446
var value = Expression . Create ( '{{' + ( options . value || $thisStr ) + '}}' , 'value' ) ;
436
447
var caption = blocks . isString ( options . caption ) && new VirtualElement ( 'option' ) ;
437
448
var option = new VirtualElement ( 'option' ) ;
438
- var children = this . _children ;
449
+ var children = this . _state && this . _state . template || this . _template || this . _children ;
439
450
var i = 0 ;
440
451
var child ;
441
-
452
+ if ( this . _sync ) {
453
+ blocks . queries . each . preprocess . call ( this , domQuery , collection ) ;
454
+ return ;
455
+ }
442
456
for ( ; i < children . length ; i ++ ) {
443
457
child = children [ i ] ;
444
458
if ( ! child . _attributes || ( child . _attributes && ! child . _attributes [ 'data-role' ] ) ) {
@@ -449,22 +463,24 @@ define([
449
463
option . _attributeExpressions . push ( value ) ;
450
464
option . _children . push ( text ) ;
451
465
option . _parent = this ;
452
- this . _children . push ( option ) ;
466
+ children . push ( option ) ;
453
467
454
468
if ( caption ) {
455
469
caption . _attributes [ 'data-role' ] = 'header' ;
456
470
caption . _innerHTML = options . caption ;
457
- this . addChild ( caption ) ;
471
+ caption . _parent = this ;
472
+ children . push ( caption ) ;
458
473
}
459
474
blocks . queries . each . preprocess . call ( this , domQuery , collection ) ;
460
475
} ,
461
476
462
477
update : function ( domQuery , collection ) {
463
478
var elementData = ElementsData . data ( this ) ;
464
479
var rawCollection = collection ( ) ;
465
- var headers = elementData . virtual . _headers ;
480
+ var state = elementData . virtual . _state ;
481
+ var headers = state && state . headers || elementData . virtual . _headers ;
466
482
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 ] ;
468
484
var rawValue = blocks . isObservable ( valueObservable ) ? valueObservable . _getValue ( ) : this . value ;
469
485
var expression ;
470
486
var value ;
0 commit comments