Fixes #811 -- allow you to pass a context when unbinding events as well.

This commit is contained in:
Jeremy Ashkenas
2012-01-12 17:09:15 -05:00
parent d514f2b4dc
commit a49bb4f3e1
2 changed files with 9 additions and 8 deletions

View File

@@ -82,10 +82,10 @@
return this;
},
// Remove one or many callbacks. If `callback` is null, removes all
// callbacks for the event. If `ev` is null, removes all bound callbacks
// for all events.
unbind : function(ev, callback) {
// Remove one or many callbacks. If `context` is null, removes all callbacks
// with that function. If `callback` is null, removes all callbacks for the
// event. If `ev` is null, removes all bound callbacks for all events.
unbind : function(ev, callback, context) {
var calls, node, prev;
if (!ev) {
this._callbacks = null;
@@ -95,9 +95,10 @@
} else if (node = calls[ev]) {
while ((prev = node) && (node = node.next)) {
if (node.callback !== callback) continue;
if (context && (context !== node.context)) continue;
prev.next = node.next;
node.context = node.callback = null;
break;
// break;
}
}
}
@@ -582,7 +583,7 @@
if (this == model.collection) {
delete model.collection;
}
model.unbind('all', this._onModelEvent);
model.unbind('all', this._onModelEvent, this);
},
// Internal method called every time a model in the set fires an event.

View File

@@ -319,7 +319,7 @@ $(document).ready(function() {
e.destroy();
ok(colE.length == 0);
ok(colF.length == 0);
equals(null, e.collection);
equals(undefined, e.collection);
});
test("Colllection: non-persisted model destroy removes from all collections", function() {
@@ -330,7 +330,7 @@ $(document).ready(function() {
e.destroy();
ok(colE.length == 0);
ok(colF.length == 0);
equals(null, e.collection);
equals(undefined, e.collection);
});
test("Collection: fetch", function() {