Browse Source

Add `updateTrait` method in Component

pull/2031/head
Artur Arseniev 7 years ago
parent
commit
e5e82feb7c
  1. 21
      src/dom_components/model/Component.js

21
src/dom_components/model/Component.js

@ -699,6 +699,25 @@ const Component = Backbone.Model.extend(Styleable).extend(
})[0]; })[0];
}, },
/**
* Update a trait
* @param {String} id The `id` or `name` of the trait
* @param {Object} props Object with the props to update
* @return {this}
* @example
* component.updateTrait('title', {
* type: 'select',
* options: [ 'Option 1', 'Option 2' ],
* });
*/
updateTrait(id, props) {
const { em } = this;
const trait = this.getTrait(id);
trait && trait.set(props);
em && em.trigger('component:toggled');
return this;
},
/** /**
* Get the trait position index by id/name. Useful in case you want to * Get the trait position index by id/name. Useful in case you want to
* replace some trait, at runtime, with something else. * replace some trait, at runtime, with something else.
@ -736,7 +755,7 @@ const Component = Backbone.Model.extend(Styleable).extend(
* @param {Options} opts Options for the add * @param {Options} opts Options for the add
* @return {Array} Array of added traits * @return {Array} Array of added traits
* @example * @example
* component.addTrat('title', { at: 1 }); // Add title trait (at option is the position index) * component.addTrat('title', { at: 1 }); // Add title trait (`at` option is the position index)
* component.addTrat({ * component.addTrat({
* type: 'checkbox', * type: 'checkbox',
* name: 'disabled', * name: 'disabled',

Loading…
Cancel
Save