reintro unkeyed each block iterations as necessary

pull/568/head
Rich-Harris 8 years ago
parent f8e73c1f36
commit b0a31dda15

@ -304,12 +304,21 @@ function unkeyed ( generator, block, state, node, snippet, { create_each_block,
if ( condition !== '' ) { if ( condition !== '' ) {
const forLoopBody = node._block.hasUpdateMethod ? const forLoopBody = node._block.hasUpdateMethod ?
node._block.hasIntroMethod ?
deindent` deindent`
if ( ${iterations}[${i}] ) { if ( ${iterations}[${i}] ) {
${iterations}[${i}].update( changed, ${params}, ${each_block_value}, ${each_block_value}[${i}], ${i} ); ${iterations}[${i}].update( changed, ${params}, ${each_block_value}, ${each_block_value}[${i}], ${i} );
} else { } else {
${iterations}[${i}] = ${create_each_block}( ${params}, ${each_block_value}, ${each_block_value}[${i}], ${i}, ${block.component} ); ${iterations}[${i}] = ${create_each_block}( ${params}, ${each_block_value}, ${each_block_value}[${i}], ${i}, ${block.component} );
${iterations}[${i}].${mountOrIntro}( ${parentNode}, ${anchor} ); }
${iterations}[${i}].intro( ${parentNode}, ${anchor} );
` :
deindent`
if ( ${iterations}[${i}] ) {
${iterations}[${i}].update( changed, ${params}, ${each_block_value}, ${each_block_value}[${i}], ${i} );
} else {
${iterations}[${i}] = ${create_each_block}( ${params}, ${each_block_value}, ${each_block_value}[${i}], ${i}, ${block.component} );
${iterations}[${i}].mount( ${parentNode}, ${anchor} );
} }
` : ` :
deindent` deindent`

@ -18,7 +18,7 @@ export function detachBetween ( before, after ) {
export function destroyEach ( iterations, detach, start ) { export function destroyEach ( iterations, detach, start ) {
for ( var i = start; i < iterations.length; i += 1 ) { for ( var i = start; i < iterations.length; i += 1 ) {
iterations[i].destroy( detach ); if ( iterations[i] ) iterations[i].destroy( detach );
} }
} }

Loading…
Cancel
Save