Skip to content

Commit

Permalink
Simplify #stopListening
Browse files Browse the repository at this point in the history
  • Loading branch information
jridgewell committed Jan 23, 2015
1 parent 8d37106 commit da8e79b
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions backbone.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
var listeningTo = this._listeningTo || (this._listeningTo = {});
listeningTo[id] || (listeningTo[id] = {obj: obj, events: {}});
obj.on(name, callback, this);
onApi(listeningTo[id].events, name, callback, this);
onApi(listeningTo[id].events, name, callback);
return this;
},

Expand All @@ -151,16 +151,14 @@
// Tell this object to stop listening to either specific events ... or
// to every object it's currently listening to.
stopListening: function(obj, name, callback) {
var listeningTo = this._listeningTo, events;
var listeningTo = this._listeningTo;
if (!listeningTo || !listenApi(this, 'stopListening', obj, name, callback)) return this;
var remove = !name && !callback;
if (obj) listeningTo = _.pick(listeningTo, obj._listenId);
for (var id in listeningTo) {
obj = listeningTo[id].obj;
events = listeningTo[id].events;
obj.off(name, callback, this);
if (!remove) events = offApi(events, name, callback, this);
if (remove || !events) delete this._listeningTo[id];
var listenee = listeningTo[id];
listenee.obj.off(name, callback, this);
var events = offApi(listenee.events, name, callback);
if (!events) delete this._listeningTo[id];
}
if (_.isEmpty(this._listeningTo)) this._listeningTo = void 0;
return this;
Expand Down

0 comments on commit da8e79b

Please sign in to comment.