Skip to content

Commit

Permalink
Add replaceWith method to Component
Browse files Browse the repository at this point in the history
  • Loading branch information
artf committed May 3, 2018
1 parent e552d80 commit db47de6
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/dom_components/model/Component.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,19 @@ const Component = Backbone.Model.extend(Styleable).extend(
coll.add(this, { at });
},

/**
* Replace a component with another one
* @param {String|Component} el Component or HTML string
* @return {Array|Component} New added component/s
* @private
*/
replaceWith(el) {
const coll = this.collection;
const at = coll.indexOf(this);
coll.remove(this);
return coll.add(el, { at });
},

/**
* Emit changes for each updated attribute
*/
Expand Down

0 comments on commit db47de6

Please sign in to comment.