diff --git a/src/generators/dom/Block.ts b/src/generators/dom/Block.ts index cd0943cfcb..0131ca1e12 100644 --- a/src/generators/dom/Block.ts +++ b/src/generators/dom/Block.ts @@ -200,9 +200,8 @@ export default class Block { this.builders.create.addLine( `${this.autofocus}.focus();` ); } - // minor hack – we need to ensure that any {{{triples}}} are detached - // first, so we append normal detach statements to detachRaw - this.builders.detachRaw.addBlock( this.builders.unmount ); // TODO reverse this, using addBlockAtStart? + // minor hack – we need to ensure that any {{{triples}}} are detached first + this.builders.unmount.addBlockAtStart( this.builders.detachRaw ); 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')},`); } else { properties.addBlock( deindent` unmount: function () { - ${this.builders.detachRaw} + ${this.builders.unmount} }, ` ); } @@ -296,8 +295,7 @@ export default class Block { properties.addBlock( `destroy: ${this.generator.helper( 'noop' )}` ); } else { properties.addBlock( deindent` - destroy: function ( detach ) { - ${!this.builders.detachRaw.isEmpty() && `if ( detach ) this.unmount();`} + destroy: function () { ${this.builders.destroy} } ` ); diff --git a/src/generators/dom/visitors/Component/Component.ts b/src/generators/dom/visitors/Component/Component.ts index 2f05389cec..106a08a92c 100644 --- a/src/generators/dom/visitors/Component/Component.ts +++ b/src/generators/dom/visitors/Component/Component.ts @@ -122,7 +122,7 @@ export default function visitComponent ( generator: DomGenerator, block: Block, } block.builders.destroy.addLine( - `${yieldFragment}.destroy( false );` + `${yieldFragment}.destroy();` ); componentInitProperties.push( `_yield: ${yieldFragment}`); diff --git a/src/generators/dom/visitors/IfBlock.ts b/src/generators/dom/visitors/IfBlock.ts index 1105617a3c..48e7b3b145 100644 --- a/src/generators/dom/visitors/IfBlock.ts +++ b/src/generators/dom/visitors/IfBlock.ts @@ -159,7 +159,7 @@ function simple ( generator: DomGenerator, block: Block, state: State, node: Nod ); 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` ${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; }); `; @@ -325,7 +326,10 @@ function compoundWithOutros ( generator: DomGenerator, block: Block, state: Stat ` ); } - block.builders.destroy.addLine( - `${if_current_block_index}${if_blocks}[ ${current_block_index} ].destroy( ${state.parentNode ? 'false' : 'detach'} );` - ); + block.builders.destroy.addLine( deindent` + ${if_current_block_index}{ + ${if_blocks}[ ${current_block_index} ].unmount(); + ${if_blocks}[ ${current_block_index} ].destroy(); + } + ` ); } diff --git a/src/shared/dom.js b/src/shared/dom.js index 3c8bb78bc0..71daedc8ce 100644 --- a/src/shared/dom.js +++ b/src/shared/dom.js @@ -16,6 +16,7 @@ export function detachBetween ( before, after ) { } } +// TODO this is out of date export function destroyEach ( iterations, detach, start ) { for ( var i = start; i < iterations.length; i += 1 ) { if ( iterations[i] ) iterations[i].destroy( detach );