Skip to content

Commit b847886

Browse files
committed
only update attributes that have changed (#279)
1 parent 2b62a29 commit b847886

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/generators/dom/visitors/attributes/addElementAttributes.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,24 @@ export default function addElementAttributes ( generator, node, local ) {
9292
// dynamic – but potentially non-string – attributes
9393
const { snippet } = generator.contextualise( value.expression );
9494

95+
const last = `last_${local.name}_${name.replace( /-/g, '_')}`;
96+
local.init.addLine( `var ${last} = ${snippet};` );
97+
9598
let updater;
96-
if (propertyName) {
97-
updater = `${local.name}.${propertyName} = ${snippet};`;
99+
if ( propertyName ) {
100+
updater = `${local.name}.${propertyName} = ${last};`;
98101
} else {
99102
generator.uses[ helper ] = true;
100-
updater = `${helper}( ${local.name}, '${name}', ${snippet} );`; // TODO use snippet both times – see note below
103+
updater = `${helper}( ${local.name}, '${name}', ${last} );`; // TODO use snippet both times – see note below
101104
}
102105

103106
local.init.addLine( updater );
104-
local.update.addLine( updater );
107+
local.update.addBlock( deindent`
108+
if ( ( __tmp = ${snippet} ) !== ${last} ) {
109+
${last} = __tmp;
110+
${updater}
111+
}
112+
` );
105113
}
106114
}
107115

Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export default {
2-
html: '<p data-value="10px"></p>'
2+
html: '<p data-value="10px"></p>'
33
};

0 commit comments

Comments
 (0)