Browse Source

Improve getInitValue of the Trait

pull/261/head
Artur Arseniev 9 years ago
parent
commit
c0e90c7a69
  1. 2
      src/dom_components/model/Component.js
  2. 15
      src/trait_manager/model/Trait.js

2
src/dom_components/model/Component.js

@ -113,9 +113,9 @@ module.exports = Backbone.Model.extend(Styleable).extend({
this.defaultCl = this.normalizeClasses(this.get('classes') || this.config.classes || []);
this.components = new Components(this.defaultC, opt);
this.components.parent = this;
this.set('attributes', this.get('attributes') || {});
this.listenTo(this, 'change:script', this.scriptUpdated);
this.listenTo(this, 'change:traits', this.traitsUpdated);
this.set('attributes', this.get('attributes') || {});
this.set('components', this.components);
this.set('classes', new Selectors(this.defaultCl));
var traits = new Traits();

15
src/trait_manager/model/Trait.js

@ -23,8 +23,21 @@ module.exports = Backbone.Model.extend({
}
},
/**
* Get the initial value of the trait
* @return {string}
*/
getInitValue() {
return this.get('value') || this.get('default');
const target = this.target;
const name = this.get('name');
let value;
if (target) {
const attrs = target.get('attributes');
value = this.get('changeProp') ? target.get(name) : attrs[name];
}
return value || this.get('value') || this.get('default');
}
});

Loading…
Cancel
Save