only update attributes that have changed (#279)

pull/294/head
Rich-Harris 9 years ago
parent 2b62a29567
commit b847886795

@ -92,16 +92,24 @@ export default function addElementAttributes ( generator, node, local ) {
// dynamic but potentially non-string attributes // dynamic but potentially non-string attributes
const { snippet } = generator.contextualise( value.expression ); const { snippet } = generator.contextualise( value.expression );
const last = `last_${local.name}_${name.replace( /-/g, '_')}`;
local.init.addLine( `var ${last} = ${snippet};` );
let updater; let updater;
if (propertyName) { if ( propertyName ) {
updater = `${local.name}.${propertyName} = ${snippet};`; updater = `${local.name}.${propertyName} = ${last};`;
} else { } else {
generator.uses[ helper ] = true; generator.uses[ helper ] = true;
updater = `${helper}( ${local.name}, '${name}', ${snippet} );`; // TODO use snippet both times see note below updater = `${helper}( ${local.name}, '${name}', ${last} );`; // TODO use snippet both times see note below
} }
local.init.addLine( updater ); local.init.addLine( updater );
local.update.addLine( updater ); local.update.addBlock( deindent`
if ( ( __tmp = ${snippet} ) !== ${last} ) {
${last} = __tmp;
${updater}
}
` );
} }
} }

Loading…
Cancel
Save