Skip to content

Commit

Permalink
Improve getInitValue of the Trait
Browse files Browse the repository at this point in the history
  • Loading branch information
artf committed Aug 17, 2017
1 parent 562e0e0 commit c0e90c7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/dom_components/model/Component.js
Expand Up @@ -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();
Expand Down
15 changes: 14 additions & 1 deletion src/trait_manager/model/Trait.js
Expand Up @@ -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');
}

});

0 comments on commit c0e90c7

Please sign in to comment.