diff --git a/src/generators/dom/visitors/EachBlock.js b/src/generators/dom/visitors/EachBlock.js index 1657a6b9ac..3d637bc5d9 100644 --- a/src/generators/dom/visitors/EachBlock.js +++ b/src/generators/dom/visitors/EachBlock.js @@ -149,6 +149,8 @@ function keyed ( generator, block, state, node, snippet, { each_block, create_ea const parentNode = state.parentNode || `${anchor}.parentNode`; + const hasIntros = node._block.hasIntroMethod; + block.builders.update.addBlock( deindent` var ${each_block_value} = ${snippet}; var ${_iterations} = []; @@ -163,11 +165,13 @@ function keyed ( generator, block, state, node, snippet, { each_block, create_ea if ( ${lookup}[ ${key} ] ) { ${consequent} + ${hasIntros && `${_iterations}[${i}].mount( ${fragment}, null );`} } else { ${_iterations}[${i}] = ${_lookup}[ ${key} ] = ${create_each_block}( ${params}, ${each_block_value}, ${each_block_value}[${i}], ${i}, ${block.component}, ${key} ); + ${hasIntros && `${_iterations}[${i}].intro( ${fragment}, null );`} } - ${_iterations}[${i}].${mountOrIntro}( ${fragment}, null ); + ${!hasIntros && `${_iterations}[${i}].mount( ${fragment}, null );`} } // remove old iterations diff --git a/test/runtime/samples/transition-js-each-block-keyed-intro/_config.js b/test/runtime/samples/transition-js-each-block-keyed-intro/_config.js new file mode 100644 index 0000000000..dc61ac5ea4 --- /dev/null +++ b/test/runtime/samples/transition-js-each-block-keyed-intro/_config.js @@ -0,0 +1,49 @@ +export default { + data: { + things: [ + { name: 'a' }, + { name: 'b' }, + { name: 'c' } + ] + }, + + test ( assert, component, target, window, raf ) { + let divs = target.querySelectorAll( 'div' ); + assert.equal( divs[0].foo, 0 ); + assert.equal( divs[1].foo, 0 ); + assert.equal( divs[2].foo, 0 ); + + raf.tick( 50 ); + assert.equal( divs[0].foo, 0.5 ); + assert.equal( divs[1].foo, 0.5 ); + assert.equal( divs[2].foo, 0.5 ); + + component.set({ + things: [ + { name: 'a' }, + { name: 'woo!' }, + { name: 'b' }, + { name: 'c' } + ] + }); + assert.htmlEqual( target.innerHTML, ` +