backbone.marionette
backbone.marionette copied to clipboard
The render:children event should be renamed show:children
This event is analogous to the region's show event. What it describes is that children were attached to the collection view. Yes, if they weren't already rendered they were rendered, but children only get rendered once, so for the most part unless children are added to the view, no child is rendered at all on subsequent triggers of this event after the first instance
https://jsfiddle.net/smgpw05w/
const myCollection = new Backbone.Collection([{ num: 4 }, { num: 2 }, { num: 1 }, { num: 3 }]);
const myCollectionView = new CollectionView({ collection: myCollection });
function countRenders(event) {
let count = 0;
this.children.each(child => {
if(child.isRendered()) count++;
});
console.log(event + ' : ' + count);
}
myCollectionView.on({
'before:render:children': _.partial(countRenders, 'before:render:children'),
'render:children': _.partial(countRenders, 'render:children')
});
someRegion.show(myCollectionView);
// before:render:children : 0
// render:children : 4
myCollectionView.setComparator('num');
// before:render:children : 4
// render:children : 4
It makes sense! :-)