Skip to content

Commit

Permalink
simplified the CollectionView.buildItemView method, to make it easier…
Browse files Browse the repository at this point in the history
… to override
  • Loading branch information
Derick Bailey committed Oct 29, 2012
1 parent 557f1ab commit f557d14
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/marionette.collectionview.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,16 @@ Marionette.CollectionView = Marionette.View.extend({
addItemView: function(item, ItemView, index){
var that = this;

var view = this.buildItemView(item, ItemView);
// get the itemViewOptions if any were specified
var itemViewOptions;
if (_.isFunction(this.itemViewOptions)){
itemViewOptions = this.itemViewOptions(item);
} else {
itemViewOptions = this.itemViewOptions;
}

// build the view
var view = this.buildItemView(item, ItemView, itemViewOptions);

// Store the child view itself so we can properly
// remove and/or close it later
Expand Down Expand Up @@ -174,15 +183,7 @@ Marionette.CollectionView = Marionette.View.extend({
},

// Build an `itemView` for every model in the collection.
buildItemView: function(item, ItemView){
var itemViewOptions;

if (_.isFunction(this.itemViewOptions)){
itemViewOptions = this.itemViewOptions(item);
} else {
itemViewOptions = this.itemViewOptions;
}

buildItemView: function(item, ItemView, itemViewOptions){
var options = _.extend({model: item}, itemViewOptions);
var view = new ItemView(options);
return view;
Expand Down

0 comments on commit f557d14

Please sign in to comment.