diff --git a/src/dom_components/model/Component.js b/src/dom_components/model/Component.js index 233073555..7ed5abb82 100644 --- a/src/dom_components/model/Component.js +++ b/src/dom_components/model/Component.js @@ -327,7 +327,11 @@ const Component = Backbone.Model.extend(Styleable).extend( * @private */ attrUpdated(m, v, opts = {}) { - this.setAttributes(this.get('attributes'), { ...opts, silent: 1 }); + const attrPrev = { ...this.previous('attributes') }; + const diff = shallowDiff(attrPrev, this.get('attributes')); + keys(diff).forEach(pr => + this.trigger(`change:attributes:${pr}`, this, diff[pr], opts) + ); }, /** @@ -351,11 +355,6 @@ const Component = Backbone.Model.extend(Styleable).extend( delete attrs.style; this.set('attributes', attrs, opts); - const attrPrev = { ...this.previous('attributes') }; - const diff = shallowDiff(attrPrev, attrs); - keys(diff).forEach(pr => - this.trigger(`change:attributes:${pr}`, this, diff[pr], opts) - ); return this; }, diff --git a/test/specs/dom_components/model/Component.js b/test/specs/dom_components/model/Component.js index a990da68e..29e2a5822 100644 --- a/test/specs/dom_components/model/Component.js +++ b/test/specs/dom_components/model/Component.js @@ -281,10 +281,10 @@ module.exports = { }); }); - test.only('setAttributes overwrites correctly', () => { + test('setAttributes overwrites correctly', () => { obj.setAttributes({ id: 'test', 'data-test': 'value', a: 'b' }); - // obj.setAttributes({ 'data-test': 'value2' }); - // expect(obj.getAttributes()).toEqual({ 'data-test': 'value2' }); + obj.setAttributes({ 'data-test': 'value2' }); + expect(obj.getAttributes()).toEqual({ 'data-test': 'value2' }); }); test('append() returns always an array', () => {