Skip to content

Commit

Permalink
Merge pull request #510 from sveltejs/gh-509
Browse files Browse the repository at this point in the history
null out else block references when they are destroyed
  • Loading branch information
Rich-Harris authored Apr 19, 2017
2 parents 7f9d91f + a0a7583 commit e627875
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/generators/dom/visitors/EachBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,16 @@ export default function visitEachBlock ( generator, block, state, node ) {
${each_block_else}.mount( ${anchor}.parentNode, ${anchor} );
} else if ( ${each_block_else} ) {
${each_block_else}.destroy( true );
${each_block_else} = null;
}
` );
} else {
block.builders.update.addBlock( deindent`
if ( ${each_block_value}.length ) {
if ( ${each_block_else} ) ${each_block_else}.destroy( true );
if ( ${each_block_else} ) {
${each_block_else}.destroy( true );
${each_block_else} = null;
}
} else if ( !${each_block_else} ) {
${each_block_else} = ${node.else._block.name}( ${params}, ${block.component} );
${each_block_else}.mount( ${anchor}.parentNode, ${anchor} );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,10 @@ export default {
assert.htmlEqual( target.innerHTML, `
<p>wombat</p>
` );

component.set({ animals: ['dinosaur'] });
assert.htmlEqual( target.innerHTML, `
<p>dinosaur</p>
` );
}
};

0 comments on commit e627875

Please sign in to comment.