-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Only update each-blocks if their value has changed #381
Comments
I did this in some example code while working on #279, I must have missed it. Has |
Honestly can't remember if it was there from the start. In any case, I realised it's slightly more complex than my example above makes out — while in this example... <ul>
{{#each cats as cat}}
<li><a target='_blank' href='{{cat.video}}'>{{cat.name}}</a></li>
{{/each}}
</ul> ...you can skip the block if {{#each comments as comment}}
<div class='comment'>
<span class='meta'>
{{comment.author}} wrote {{elapsed(comment.time, time}} ago:
</span>
{{{comment.html}}}
</div>
{{/each}} In that example you'd need to update members of the block if // ...
update: function ( changed, root ) {
var __tmp;
if ( 'comments' in changed || 'time' in changed ) {
var eachBlock_value = root.comments;
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;
}
}, So we'd need to capture all the dependencies of any expressions used in the block. (We already get this for free in |
Only update each blocks when their dependencies have changed
Fixed in 1.16 |
The 'Each blocks' example in the REPL produces this code:
If it were this instead...
...we'd prevent a lot of unnecessary work.
The text was updated successfully, but these errors were encountered: