Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixes issue #191 with cleanup not being called on subviews.

  • Loading branch information...
commit 498ad551909662a38517cf58d08cfae2430634d8 1 parent cfce2ed
BJTerry authored
Showing with 33 additions and 0 deletions.
  1. +3 −0  backbone.layoutmanager.js
  2. +30 −0 test/views.js
View
3  backbone.layoutmanager.js
@@ -467,6 +467,9 @@ var LayoutManager = Backbone.View.extend({
// Clean out the events.
LayoutManager.cleanViews(view);
+ // Since we are removing this view, force subviews to remove
+ view._removeViews(true);
+
// Remove the View completely.
view.$el.remove();
View
30 test/views.js
@@ -1567,6 +1567,36 @@ test("cleanup called on View w/o parent when removed", 1, function() {
ok(hit, "Cleanup was successfully hit");
});
+asyncTest("cleanup called on subview when parent view removed", function() {
+ expect(2);
+ var hitSub = false;
+ var hitParent = false;
+
+ var subview = new this.View({msg: "Right"});
+
+ subview = _.extend(subview, {
+ cleanup: function(){
+ hitSub = true;
+ }});
+
+
+ var main = _.extend(new Backbone.Layout({
+ template: "#main",
+ views: {
+ ".right": subview
+ }
+ }), {cleanup: function() {hitParent = true;}});
+
+ _.extend(main, {cleanup: function(){ hitParent=true;}});
+
+ main.render().then(function() {
+ main.remove();
+ ok(hitSub, "Cleanup successfully called on a subview when parent removed");
+ ok(hitParent, "Cleanup successfully called on parent view when removed");
+ start();
+ });
+});
+
test("attached even if already rendered", 1, function() {
var view = new Backbone.LayoutView({ className: "test" });
view.render();
Please sign in to comment.
Something went wrong with that request. Please try again.