only update attributes that have changed (#279)

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

@ -92,16 +92,24 @@ export default function addElementAttributes ( generator, node, local ) {
// dynamic but potentially non-string attributes
const { snippet } = generator.contextualise( value.expression );
const last = `last_${local.name}_${name.replace( /-/g, '_')}`;
local.init.addLine( `var ${last} = ${snippet};` );
let updater;
if (propertyName) {
updater = `${local.name}.${propertyName} = ${snippet};`;
if ( propertyName ) {
updater = `${local.name}.${propertyName} = ${last};`;
} else {
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.update.addLine( updater );
local.update.addBlock( deindent`
if ( ( __tmp = ${snippet} ) !== ${last} ) {
${last} = __tmp;
${updater}
}
` );
}
}

@ -1,3 +1,3 @@
export default {
html: '<p data-value="10px"></p>'
html: '<p data-value="10px"></p>'
};

Loading…
Cancel
Save