Skip to content

Commit

Permalink
cleaning up the getItemViewContainer method a bit, and adding a bette…
Browse files Browse the repository at this point in the history
…r error message when the container element is not found. closes marionettejs#200
  • Loading branch information
Derick Bailey committed Sep 29, 2012
1 parent 5b1ec98 commit f5fd8bd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion spec/javascripts/compositeView-itemViewContainer.spec.js
Expand Up @@ -78,7 +78,7 @@ describe("composite view - itemViewContainer", function(){
});

it("should throw an error", function(){
expect(function(){compositeView.render()}).toThrow("Missing `itemViewContainer`");
expect(function(){compositeView.render()}).toThrow("The specified `itemViewContainer` was not found: #missing-container");
});
});

Expand Down
30 changes: 16 additions & 14 deletions src/backbone.marionette.compositeview.js
Expand Up @@ -87,23 +87,25 @@ Marionette.CompositeView = Marionette.CollectionView.extend({
// Internal method to ensure an `$itemViewContainer` exists, for the
// `appendHtml` method to use.
getItemViewContainer: function(containerView){
var container;
if ("$itemViewContainer" in containerView){
container = containerView.$itemViewContainer;
} else {
if (containerView.itemViewContainer){
container = containerView.$(_.result(containerView, "itemViewContainer"));

if (container.length <= 0) {
var err = new Error("Missing `itemViewContainer`");
err.name = "ItemViewContainerMissingError";
throw err;
}
} else {
container = containerView.$el;
return containerView.$itemViewContainer;
}

var container;
if (containerView.itemViewContainer){

container = containerView.$(_.result(containerView, "itemViewContainer"));
if (container.length <= 0) {
var err = new Error("The specified `itemViewContainer` was not found: " + containerView.itemViewContainer);
err.name = "ItemViewContainerMissingError";
throw err;
}
containerView.$itemViewContainer = container;

} else {
container = containerView.$el;
}

containerView.$itemViewContainer = container;
return container;
},

Expand Down

0 comments on commit f5fd8bd

Please sign in to comment.