Browse Source

Add `getTraitIndex` method to Component

pull/2031/head
Artur Arseniev 8 years ago
parent
commit
0378527d52
  1. 14
      src/dom_components/model/Component.js

14
src/dom_components/model/Component.js

@ -677,6 +677,20 @@ const Component = Backbone.Model.extend(Styleable).extend(
})[0];
},
/**
* Get the trait position index by id/name. Useful in case you want to
* replace some trait, at runtime, with something else.
* @param {String} id The `id` or `name` of the trait
* @return {Number} Index position of the current trait
* @example
* const traitTitle = component.getTraitIndex('title');
* console.log(traitTitle); // 1
*/
getTraitIndex(id) {
const trait = this.getTrait(id);
return trait ? this.get('traits').indexOf(trait) : trait;
},
/**
* Normalize input classes from array to array of objects
* @param {Array} arr

Loading…
Cancel
Save