mirror of
https://github.com/jashkenas/backbone.git
synced 2026-04-08 03:00:26 -04:00
Fixes #811 -- allow you to pass a context when unbinding events as well.
This commit is contained in:
13
backbone.js
13
backbone.js
@@ -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.
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user