Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

.cleanup() not called on subviews with .remove() #191

Closed
BJTerry opened this Issue Oct 25, 2012 · 3 comments

Comments

Projects
None yet
2 participants

BJTerry commented Oct 25, 2012

When .remove() is called on a view that has subviews, the .cleanup() method for that parent view is called, but it doesn't call .cleanup() on views in its this.views. It seems that .cleanup() should cascade down the view hierarchy so that all of the events and other objects can be cleaned up.

Owner

tbranyen commented Oct 26, 2012

Every nested view has removed called on it which should call cleanup cascading down. I'll investigate.

BJTerry commented Oct 26, 2012

This is a motivating test case that fails.

asyncTest("cleanup called on subview when parent view removed", function() {
  expect(1);
  var hit = false;

  var Subview = _.extend(this.View, {
    cleanup: function(){
      hit = true;
  }});

  var main = new Backbone.Layout({
    template: "#main",
    views: {
      ".right": new Subview({ msg: "Right" })
    }
  });

  main.render().then(function() {
    main.remove();   
    ok(hit, "cleanup successfully called on a subview when parent removed");
    start();
  });
});

BJTerry commented Oct 27, 2012

The above motivating test case doesn't work. A fixed version is included in the pull request.

@BJTerry BJTerry pushed a commit to BJTerry/backbone.layoutmanager that referenced this issue Oct 27, 2012

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

@BJTerry BJTerry pushed a commit to BJTerry/backbone.layoutmanager that referenced this issue Oct 27, 2012

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

@tbranyen tbranyen added a commit that referenced this issue Oct 27, 2012

@tbranyen tbranyen Merge pull request #195 from BJTerry/issue-191
Fixes issue #191 with cleanup not being called on subviews.
9ed472b

@tbranyen tbranyen closed this Oct 28, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment