Browse Source

Listen BlocksView reset

no-jquery^2
Artur Arseniev 9 years ago
parent
commit
074b7bc7e4
  1. 11
      src/block_manager/index.js
  2. 12
      src/block_manager/view/BlocksView.js

11
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: '<div>Content</div>'}
* ]);
*
* // Back to blocks from the global collection
* blockManager.render();
*/
render(blocks) {
const toRender = blocks || this.getAll().models;

12
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({
</div>
`;
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;

Loading…
Cancel
Save