diff --git a/src/generators/Generator.js b/src/generators/Generator.js index 8d43de8bf8..b1b4154b1d 100644 --- a/src/generators/Generator.js +++ b/src/generators/Generator.js @@ -151,7 +151,7 @@ export default class Generator { }; } - findDependencies ( contextDependencies, expression ) { + findDependencies ( contextDependencies, indexes, expression ) { if ( expression._dependencies ) return expression._dependencies; let scope = annotateWithScopes( expression ); @@ -170,7 +170,7 @@ export default class Generator { if ( contextDependencies.has( name ) ) { dependencies.push( ...contextDependencies.get( name ) ); - } else { + } else if ( !indexes.has( name ) ) { dependencies.push( name ); } diff --git a/src/generators/dom/Block.js b/src/generators/dom/Block.js index 11889070fa..093fe214e2 100644 --- a/src/generators/dom/Block.js +++ b/src/generators/dom/Block.js @@ -75,7 +75,7 @@ export default class Block { } findDependencies ( expression ) { - return this.generator.findDependencies( this.contextDependencies, expression ); + return this.generator.findDependencies( this.contextDependencies, this.indexes, expression ); } mount ( name, parentNode ) { diff --git a/test/js/samples/each-block-changed-check/expected.js b/test/js/samples/each-block-changed-check/expected.js index 1334c840e7..2d1576571b 100644 --- a/test/js/samples/each-block-changed-check/expected.js +++ b/test/js/samples/each-block-changed-check/expected.js @@ -62,19 +62,25 @@ function create_main_fragment ( root, component ) { }; } -function create_each_block ( root, each_block_value, comment, comment_index, component ) { +function create_each_block ( root, each_block_value, comment, i, component ) { var div = createElement( 'div' ); div.className = "comment"; + var strong = createElement( 'strong' ); + appendNode( strong, div ); + var text_value = i; + var text = createText( text_value ); + appendNode( text, strong ); + appendNode( createText( "\n\n\t\t" ), div ); var span = createElement( 'span' ); appendNode( span, div ); span.className = "meta"; - var text_value = comment.author; - var text = createText( text_value ); - appendNode( text, span ); - appendNode( createText( " wrote " ), span ); - var text_2_value = root.elapsed(comment.time, root.time); + var text_2_value = comment.author; var text_2 = createText( text_2_value ); appendNode( text_2, span ); + appendNode( createText( " wrote " ), span ); + var text_4_value = root.elapsed(comment.time, root.time); + var text_4 = createText( text_4_value ); + appendNode( text_4, span ); appendNode( createText( " ago:" ), span ); appendNode( createText( "\n\n\t\t" ), div ); var raw_before = createElement( 'noscript' ); @@ -89,15 +95,19 @@ function create_each_block ( root, each_block_value, comment, comment_index, com insertNode( div, target, anchor ); }, - update: function ( changed, root, each_block_value, comment, comment_index ) { - if ( text_value !== ( text_value = comment.author ) ) { + update: function ( changed, root, each_block_value, comment, i ) { + if ( text_value !== ( text_value = i ) ) { text.data = text_value; } - if ( text_2_value !== ( text_2_value = root.elapsed(comment.time, root.time) ) ) { + if ( text_2_value !== ( text_2_value = comment.author ) ) { text_2.data = text_2_value; } + if ( text_4_value !== ( text_4_value = root.elapsed(comment.time, root.time) ) ) { + text_4.data = text_4_value; + } + if ( raw_value !== ( raw_value = comment.html ) ) { detachBetween( raw_before, raw_after ); raw_before.insertAdjacentHTML( 'afterend', raw_value ); diff --git a/test/js/samples/each-block-changed-check/input.html b/test/js/samples/each-block-changed-check/input.html index 16ec9e2ba8..5a80a1a6c1 100644 --- a/test/js/samples/each-block-changed-check/input.html +++ b/test/js/samples/each-block-changed-check/input.html @@ -1,5 +1,7 @@ -{{#each comments as comment}} +{{#each comments as comment, i}}
+ {{i}} + {{comment.author}} wrote {{elapsed(comment.time, time)}} ago: