null out else block references when they are destroyed — fixes #509

pull/510/head
Rich-Harris 8 years ago
parent 4012414fa7
commit a0a7583fb8

@ -66,12 +66,16 @@ export default function visitEachBlock ( generator, block, state, node ) {
${each_block_else}.mount( ${anchor}.parentNode, ${anchor} ); ${each_block_else}.mount( ${anchor}.parentNode, ${anchor} );
} else if ( ${each_block_else} ) { } else if ( ${each_block_else} ) {
${each_block_else}.destroy( true ); ${each_block_else}.destroy( true );
${each_block_else} = null;
} }
` ); ` );
} else { } else {
block.builders.update.addBlock( deindent` block.builders.update.addBlock( deindent`
if ( ${each_block_value}.length ) { 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} ) { } else if ( !${each_block_else} ) {
${each_block_else} = ${node.else._block.name}( ${params}, ${block.component} ); ${each_block_else} = ${node.else._block.name}( ${params}, ${block.component} );
${each_block_else}.mount( ${anchor}.parentNode, ${anchor} ); ${each_block_else}.mount( ${anchor}.parentNode, ${anchor} );

@ -23,5 +23,10 @@ export default {
assert.htmlEqual( target.innerHTML, ` assert.htmlEqual( target.innerHTML, `
<p>wombat</p> <p>wombat</p>
` ); ` );
component.set({ animals: ['dinosaur'] });
assert.htmlEqual( target.innerHTML, `
<p>dinosaur</p>
` );
} }
}; };

Loading…
Cancel
Save