Browse Source

Emit changes for each updated attribute

pull/712/head
Artur Arseniev 9 years ago
parent
commit
87e4b0a75a
  1. 12
      src/dom_components/model/Component.js

12
src/dom_components/model/Component.js

@ -163,6 +163,7 @@ module.exports = Backbone.Model.extend(Styleable).extend({
this.listenTo(this, 'change:script', this.scriptUpdated);
this.listenTo(this, 'change:traits', this.traitsUpdated);
this.listenTo(this, 'change:tagName', this.tagUpdated);
this.listenTo(this, 'change:attributes', this.attrUpdated);
this.loadTraits();
this.initClasses();
this.initComponents();
@ -218,6 +219,17 @@ module.exports = Backbone.Model.extend(Styleable).extend({
},
/**
* Emit changes for each updated attribute
*/
attrUpdated() {
const attrPrev = { ...this.previous('attributes') };
const attrCurrent = { ...this.get('attributes') };
const diff = shallowDiff(attrPrev, attrCurrent);
keys(diff).forEach(pr => this.trigger(`change:attributes:${pr}`));
},
/**
* Update attributes of the model
* @param {Object} attrs Key value attributes

Loading…
Cancel
Save