Permalink
Browse files

Correct cleanViews invocation of cleanup methods

Ensure that cleanViews invokes cleanup methods in the context of the
target layout.
  • Loading branch information...
1 parent f93256d commit ce125ce25b2614b52a13dd61a72fd6b9fabcccc0 @jugglinmike jugglinmike committed Mar 24, 2013
Showing with 17 additions and 1 deletion.
  1. +6 −1 backbone.layoutmanager.js
  2. +11 −0 test/views.js
@@ -613,6 +613,8 @@ var LayoutManager = Backbone.View.extend({
cleanViews: function(views) {
// Clear out all existing views.
_.each(aConcat.call([], views), function(view) {
+ var cleanup;
+
// Remove all custom events attached to this View.
view.unbind();
@@ -631,7 +633,10 @@ var LayoutManager = Backbone.View.extend({
// If a custom cleanup method was provided on the view, call it after
// the initial cleanup is done
- _.result(view.getAllOptions(), "cleanup");
+ cleanup = view.getAllOptions().cleanup;
+ if (_.isFunction(cleanup)) {
+ cleanup.call(view);
+ }
});
},
View
@@ -1964,4 +1964,15 @@ test("getViews returns an empty array for unrecognized selectors", function() {
equal(layout.getViews('.whats-the-buzz').value().length, 0);
});
+// https://github.com/tbranyen/backbone.layoutmanager/issues/328
+test("cleanViews invokes cleanup method in the context of the layout", function() {
+ var layout = new Backbone.Layout({
+ cleanup: function() {
+ equal(this, layout);
+ }
+ });
+
+ Backbone.Layout.cleanViews(layout);
+});
+
})(typeof global !== "undefined" ? global : this);

0 comments on commit ce125ce

Please sign in to comment.