pull/603/head
Rich Harris 8 years ago
parent 5c055a9f0c
commit 8a57ae8b54

@ -200,9 +200,8 @@ export default class Block {
this.builders.create.addLine( `${this.autofocus}.focus();` ); this.builders.create.addLine( `${this.autofocus}.focus();` );
} }
// minor hack we need to ensure that any {{{triples}}} are detached // minor hack we need to ensure that any {{{triples}}} are detached first
// first, so we append normal detach statements to detachRaw this.builders.unmount.addBlockAtStart( this.builders.detachRaw );
this.builders.detachRaw.addBlock( this.builders.unmount ); // TODO reverse this, using addBlockAtStart?
const properties = new CodeBuilder(); const properties = new CodeBuilder();
@ -282,12 +281,12 @@ export default class Block {
} }
} }
if ( this.builders.detachRaw.isEmpty() ) { if ( this.builders.unmount.isEmpty() ) {
properties.addBlock( `unmount: ${this.generator.helper('noop')},`); properties.addBlock( `unmount: ${this.generator.helper('noop')},`);
} else { } else {
properties.addBlock( deindent` properties.addBlock( deindent`
unmount: function () { unmount: function () {
${this.builders.detachRaw} ${this.builders.unmount}
}, },
` ); ` );
} }
@ -296,8 +295,7 @@ export default class Block {
properties.addBlock( `destroy: ${this.generator.helper( 'noop' )}` ); properties.addBlock( `destroy: ${this.generator.helper( 'noop' )}` );
} else { } else {
properties.addBlock( deindent` properties.addBlock( deindent`
destroy: function ( detach ) { destroy: function () {
${!this.builders.detachRaw.isEmpty() && `if ( detach ) this.unmount();`}
${this.builders.destroy} ${this.builders.destroy}
} }
` ); ` );

@ -122,7 +122,7 @@ export default function visitComponent ( generator: DomGenerator, block: Block,
} }
block.builders.destroy.addLine( block.builders.destroy.addLine(
`${yieldFragment}.destroy( false );` `${yieldFragment}.destroy();`
); );
componentInitProperties.push( `_yield: ${yieldFragment}`); componentInitProperties.push( `_yield: ${yieldFragment}`);

@ -159,7 +159,7 @@ function simple ( generator: DomGenerator, block: Block, state: State, node: Nod
); );
block.builders.destroy.addLine( block.builders.destroy.addLine(
`${if_name}${name}.destroy( false );` `${if_name}${name}.destroy();`
); );
} }
@ -277,7 +277,8 @@ function compoundWithOutros ( generator: DomGenerator, block: Block, state: Stat
const destroyOldBlock = deindent` const destroyOldBlock = deindent`
${name}.outro( function () { ${name}.outro( function () {
${if_blocks}[ ${previous_block_index} ].destroy( true ); ${if_blocks}[ ${previous_block_index} ].unmount();
${if_blocks}[ ${previous_block_index} ].destroy();
${if_blocks}[ ${previous_block_index} ] = null; ${if_blocks}[ ${previous_block_index} ] = null;
}); });
`; `;
@ -325,7 +326,10 @@ function compoundWithOutros ( generator: DomGenerator, block: Block, state: Stat
` ); ` );
} }
block.builders.destroy.addLine( block.builders.destroy.addLine( deindent`
`${if_current_block_index}${if_blocks}[ ${current_block_index} ].destroy( ${state.parentNode ? 'false' : 'detach'} );` ${if_current_block_index}{
); ${if_blocks}[ ${current_block_index} ].unmount();
${if_blocks}[ ${current_block_index} ].destroy();
}
` );
} }

@ -16,6 +16,7 @@ export function detachBetween ( before, after ) {
} }
} }
// TODO this is out of date
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 ) {
if ( iterations[i] ) iterations[i].destroy( detach ); if ( iterations[i] ) iterations[i].destroy( detach );

Loading…
Cancel
Save