DRY out block.tmp stuff

pull/453/head
Rich-Harris 8 years ago
parent 8148230e49
commit 67967b1a83

@ -104,17 +104,16 @@ export default class Block {
if ( this.builders.update.isEmpty() ) {
properties.addBlock( `update: ${this.generator.helper( 'noop' )},` );
} else {
if ( this._tmp ) this.builders.update.addBlockAtStart( `var ${this._tmp};` );
properties.addBlock( deindent`
update: function ( changed, ${this.params.join( ', ' )} ) {
${this.tmp ? `var ${this.tmp};` : ''}
${this.builders.update}
},
` );
}
if ( this.builders.destroy.isEmpty() ) {
properties.addBlock( `destroy: ${this.generator.helper( 'noop' )},` );
properties.addBlock( `destroy: ${this.generator.helper( 'noop' )}` );
} else {
properties.addBlock( deindent`
destroy: function ( detach ) {
@ -133,4 +132,9 @@ export default class Block {
}
`;
}
tmp () {
if ( !this._tmp ) this._tmp = this.getUniqueName( 'tmp' );
return this._tmp;
}
}

@ -8,11 +8,9 @@ export default function visitMustacheTag ( generator, block, state, node ) {
block.builders.create.addLine( `var last_${name} = ${snippet};` );
block.addElement( name, `${generator.helper( 'createText' )}( last_${name} )`, state.parentNode, true );
if ( !block.tmp ) block.tmp = block.getUniqueName( 'tmp' );
block.builders.update.addBlock( deindent`
if ( ( ${block.tmp} = ${snippet} ) !== last_${name} ) {
${name}.data = last_${name} = ${block.tmp};
if ( ( ${block.tmp()} = ${snippet} ) !== last_${name} ) {
${name}.data = last_${name} = ${block.tmp()};
}
` );
}

@ -25,11 +25,9 @@ export default function visitRawMustacheTag ( generator, block, state, node ) {
block.builders.create.addLine( mountStatement );
}
if ( !block.tmp ) block.tmp = block.getUniqueName( 'tmp' );
block.builders.update.addBlock( deindent`
if ( ( ${block.tmp} = ${snippet} ) !== last_${name} ) {
last_${name} = ${block.tmp};
if ( ( ${block.tmp()} = ${snippet} ) !== last_${name} ) {
last_${name} = ${block.tmp()};
${detachStatement}
${mountStatement}
}

@ -106,11 +106,9 @@ export default function addElementAttributes ( generator, block, node, local ) {
local.create.addLine( updater );
if ( !block.tmp ) block.tmp = block.getUniqueName( 'tmp' );
local.update.addBlock( deindent`
if ( ( ${block.tmp} = ${snippet} ) !== ${last} ) {
${last} = ${block.tmp};
if ( ( ${block.tmp()} = ${snippet} ) !== ${last} ) {
${last} = ${block.tmp()};
${updater}
}
` );

Loading…
Cancel
Save