diff --git a/src/block_manager/index.js b/src/block_manager/index.js index 865383c3e..deb81bd1d 100644 --- a/src/block_manager/index.js +++ b/src/block_manager/index.js @@ -198,14 +198,21 @@ module.exports = () => { * @param {Array} blocks Blocks to render, without the argument will render * all global blocks * @example - * // Render all blocks + * // Render all blocks (inside the global collection) * blockManager.render(); * - * // Render some blocks + * // Render new set of blocks * const blocks = blockManager.getAll(); * blockManager.render(blocks.filter( * block => block.get('category') == 'sections' * )); + * // Or a new set from an array + * blockManager.render([ + * {label: 'Label text', content: '
Content
'} + * ]); + * + * // Back to blocks from the global collection + * blockManager.render(); */ render(blocks) { const toRender = blocks || this.getAll().models; diff --git a/src/block_manager/view/BlocksView.js b/src/block_manager/view/BlocksView.js index 33c0d81fb..75cfdf25c 100644 --- a/src/block_manager/view/BlocksView.js +++ b/src/block_manager/view/BlocksView.js @@ -14,7 +14,9 @@ module.exports = Backbone.View.extend({ this.noCatClass = `${ppfx}blocks-no-cat`; this.blockContClass = `${ppfx}blocks-c`; this.catsClass = `${ppfx}block-categories`; - this.listenTo(this.collection, 'add', this.addTo); + const coll = this.collection; + this.listenTo(coll, 'add', this.addTo); + this.listenTo(coll, 'reset', this.render); this.em = this.config.em; this.tac = 'test-tac'; this.grabbingCls = this.ppfx + 'grabbing'; @@ -167,8 +169,7 @@ module.exports = Backbone.View.extend({ }, render() { - var ppfx = this.ppfx; - var frag = document.createDocumentFragment(); + const frag = document.createDocumentFragment(); this.catsEl = null; this.blocksEl = null; this.renderedCategories = []; @@ -179,10 +180,7 @@ module.exports = Backbone.View.extend({ `; - this.collection.each(function(model){ - this.add(model, frag); - }, this); - + this.collection.each(model => this.add(model, frag)); this.append(frag); this.$el.addClass(this.blockContClass + 's') return this;