Skip to content

Commit

Permalink
Fix bug with onRenderCollection call
Browse files Browse the repository at this point in the history
  • Loading branch information
samccone committed Jun 20, 2014
1 parent 7917f60 commit b2fe9b6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
24 changes: 24 additions & 0 deletions spec/javascripts/collectionView.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,30 @@ describe('collection view', function() {
});
});

describe('when rendering a collection view and accessing children via the DOM', function() {
beforeEach(function() {
var suite = this;

this.CollectionView = this.MockCollectionView.extend({
onRenderCollection: function() {
this.onRenderChildCount = this.$(suite.ChildView.prototype.tagName).length;
}
});

this.collection = new Backbone.Collection([{foo: 'bar'}, {foo: 'baz'}]);

this.collectionView = new this.CollectionView({
collection: this.collection
});

this.collectionView.render();
});

it('should find the expected number of childen', function() {
expect(this.collectionView.onRenderChildCount).to.equal(this.collection.length);
});
});

describe('when rendering a collection view without a collection', function() {
beforeEach(function() {
this.collectionView = new this.MockCollectionView();
Expand Down
5 changes: 3 additions & 2 deletions spec/javascripts/compositeView-childViewContainer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,11 @@ describe('composite view - childViewContainer', function() {
describe('when a composite view has the "childViewContainer" specified as a function', function() {
beforeEach(function() {
this.templateFn = _.template('<div><h1>composite view</h1><ul></ul></div>');

this.collection = new Backbone.Collection([{}]);
this.CompositeView = Backbone.Marionette.CompositeView.extend({
childView: this.ItemView,
template: this.templateFn
template: this.templateFn,
collection: this.collection
});

this.compositeView = new this.CompositeView();
Expand Down
12 changes: 5 additions & 7 deletions src/marionette.collectionview.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,20 +136,18 @@ Marionette.CollectionView = Marionette.View.extend({
// more control over events being triggered, around the rendering
// process
_renderChildren: function() {
this.startBuffering();

this.destroyEmptyView();
this.destroyChildren();

if (!this.isEmpty(this.collection)) {
if (this.isEmpty(this.collection)) {
this.showEmptyView();
} else {
this.triggerMethod('before:render:collection', this);
this.startBuffering();
this.showCollection();
this.endBuffering();
this.triggerMethod('render:collection', this);
} else {
this.showEmptyView();
}

this.endBuffering();
},

// Internal method to loop through collection and show each child view.
Expand Down

0 comments on commit b2fe9b6

Please sign in to comment.