Improve teardown code by unifying detach branches

pull/110/head
mrkishi 8 years ago
parent 5770048855
commit 119ad1432a

@ -27,8 +27,8 @@ export default function generate ( parsed, source, options ) {
` );
}
if ( isToplevel ) {
generator.current.teardownStatements.push( deindent`
if ( detach ) ${name}.parentNode.removeChild( ${name} );
generator.current.detachStatements.push( deindent`
${name}.parentNode.removeChild( ${name} );
` );
}
},
@ -72,6 +72,10 @@ export default function generate ( parsed, source, options ) {
teardown: function ( detach ) {
${fragment.teardownStatements.join( '\n\n' )}
if ( detach ) {
${fragment.detachStatements.join( '\n\n' )}
}
}
};
}
@ -255,6 +259,7 @@ export default function generate ( parsed, source, options ) {
initStatements: [],
mountStatements: [],
updateStatements: [],
detachStatements: [],
teardownStatements: [],
contexts: {},

@ -102,6 +102,7 @@ export default {
return `var ${contextName} = ${listName}[${indexName}];`;
}).join( '\n' ) ],
detachStatements: [],
teardownStatements: [],
counter: counter(),

@ -17,6 +17,7 @@ export default {
init: [],
mount: [],
update: [],
detach: [],
teardown: []
};
@ -138,7 +139,7 @@ export default {
local.init.unshift( render );
if ( isToplevel ) {
local.teardown.push( `if ( detach ) ${name}.parentNode.removeChild( ${name} );` );
local.detach.push( `${name}.parentNode.removeChild( ${name} );` );
}
}
@ -152,6 +153,7 @@ export default {
generator.current.initStatements.push( local.init.join( '\n' ) );
if ( local.update.length ) generator.current.updateStatements.push( local.update.join( '\n' ) );
if ( local.mount.length ) generator.current.mountStatements.push( local.mount.join( '\n' ) );
generator.current.detachStatements.push( local.detach.join( '\n' ) );
generator.current.teardownStatements.push( local.teardown.join( '\n' ) );
generator.push({

@ -13,6 +13,7 @@ function generateBlock ( generator, node, name ) {
initStatements: [],
mountStatements: [],
updateStatements: [],
detachStatements: [],
teardownStatements: [],
counter: counter()

Loading…
Cancel
Save