From db47de6ecf8a37774be8fc457c06c271c73187d5 Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Thu, 3 May 2018 23:32:59 +0200 Subject: [PATCH] Add `replaceWith` method to Component --- src/dom_components/model/Component.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/dom_components/model/Component.js b/src/dom_components/model/Component.js index 55fb44fa9..46b5d78a5 100644 --- a/src/dom_components/model/Component.js +++ b/src/dom_components/model/Component.js @@ -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 */