Closed
Description
The 'Each blocks' example in the REPL produces this code:
// ...
update: function ( changed, root ) {
var __tmp;
var eachBlock_value = root.cats;
for ( var i = 0; i < eachBlock_value.length; i += 1 ) {
if ( !eachBlock_iterations[i] ) {
eachBlock_iterations[i] = renderEachBlock( root, eachBlock_value, eachBlock_value[i], i, component );
eachBlock_iterations[i].mount( eachBlock_anchor.parentNode, eachBlock_anchor );
} else {
eachBlock_iterations[i].update( changed, root, eachBlock_value, eachBlock_value[i], i );
}
}
teardownEach( eachBlock_iterations, true, eachBlock_value.length );
eachBlock_iterations.length = eachBlock_value.length;
},
If it were this instead...
// ...
update: function ( changed, root ) {
var __tmp;
if ( 'cats' in changed ) {
var eachBlock_value = root.cats;
for ( var i = 0; i < eachBlock_value.length; i += 1 ) {
if ( !eachBlock_iterations[i] ) {
eachBlock_iterations[i] = renderEachBlock( root, eachBlock_value, eachBlock_value[i], i, component );
eachBlock_iterations[i].mount( eachBlock_anchor.parentNode, eachBlock_anchor );
} else {
eachBlock_iterations[i].update( changed, root, eachBlock_value, eachBlock_value[i], i );
}
}
teardownEach( eachBlock_iterations, true, eachBlock_value.length );
eachBlock_iterations.length = eachBlock_value.length;
}
},
...we'd prevent a lot of unnecessary work.