Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #1714 from RStankov/view-dispose-can-work-with-nor…

…mal-objects

Check if model/collection support .off when disposing of the view
  • Loading branch information...
commit bc4c7a339d38261571c2386e56d4b0fb48db9578 2 parents f0586cf + 4a20d66
@jashkenas authored
Showing with 10 additions and 5 deletions.
  1. +2 −2 backbone.js
  2. +8 −3 test/view.js
View
4 backbone.js
@@ -1234,8 +1234,8 @@
// memory leaks.
dispose: function() {
this.undelegateEvents();
- if (this.model) this.model.off(null, null, this);
- if (this.collection) this.collection.off(null, null, this);
+ if (this.model && this.model.off) this.model.off(null, null, this);
+ if (this.collection && this.collection.off) this.collection.off(null, null, this);
return this;
},
View
11 test/view.js
@@ -286,11 +286,11 @@ $(document).ready(function() {
test("dispose", 0, function() {
var View = Backbone.View.extend({
events: {
- click: function() { ok(false); }
+ click: function() { fail(); }
},
initialize: function() {
- this.model.on('all x', function(){ ok(false); }, this);
- this.collection.on('all x', function(){ ok(false); }, this);
+ this.model.on('all x', function(){ fail(); }, this);
+ this.collection.on('all x', function(){ fail(); }, this);
}
});
@@ -305,6 +305,11 @@ $(document).ready(function() {
view.$el.click();
});
+ test("dispose with non Backbone objects", 0, function() {
+ var view = new Backbone.View({model: {}, collection: {}});
+ view.dispose();
+ });
+
test("view#remove calls dispose.", 1, function() {
var view = new Backbone.View();
Please sign in to comment.
Something went wrong with that request. Please try again.