From 9a43593a9e40b8cc7ef9cecf40b631dd26e01144 Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Sat, 6 May 2017 13:02:12 -0400 Subject: [PATCH] reintro unkeyed each block iterations as necessary --- src/generators/dom/visitors/EachBlock.js | 25 ++++++++++++++++-------- src/shared/dom.js | 2 +- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/generators/dom/visitors/EachBlock.js b/src/generators/dom/visitors/EachBlock.js index dcf556ccfd..d30406598c 100644 --- a/src/generators/dom/visitors/EachBlock.js +++ b/src/generators/dom/visitors/EachBlock.js @@ -304,14 +304,23 @@ function unkeyed ( generator, block, state, node, snippet, { create_each_block, if ( condition !== '' ) { const forLoopBody = node._block.hasUpdateMethod ? - 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}].${mountOrIntro}( ${parentNode}, ${anchor} ); - } - ` : + node._block.hasIntroMethod ? + 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}].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` ${iterations}[${i}] = ${create_each_block}( ${params}, ${each_block_value}, ${each_block_value}[${i}], ${i}, ${block.component} ); ${iterations}[${i}].${mountOrIntro}( ${parentNode}, ${anchor} ); diff --git a/src/shared/dom.js b/src/shared/dom.js index 6280783cb6..3c8bb78bc0 100644 --- a/src/shared/dom.js +++ b/src/shared/dom.js @@ -18,7 +18,7 @@ export function detachBetween ( before, after ) { export function destroyEach ( iterations, detach, start ) { for ( var i = start; i < iterations.length; i += 1 ) { - iterations[i].destroy( detach ); + if ( iterations[i] ) iterations[i].destroy( detach ); } }