Skip to content

Commit

Permalink
fix[DETACH EVENT] Fix bug when detaching all events
Browse files Browse the repository at this point in the history
  • Loading branch information
Boris CERATI committed Apr 23, 2020
1 parent 870fb95 commit 090ccbb
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,22 @@
* @param {callback} callback - the callback to remove (undefined to remove all of them).
*/
detach: function(eventName, callback) {
if (callback === undefined) {
that.listeners[eventName] = [];
return true;
}

for (var k in that.listeners[eventName]) {
if (
that.listeners[eventName].hasOwnProperty(k) &&
(that.listeners[eventName][k].callback === callback ||
callback === undefined)
that.listeners[eventName][k].callback === callback
) {
that.listeners[eventName].splice(k, 1);
return this.detach(eventName, callback);
}
}

return true;
},

/**
Expand Down

0 comments on commit 090ccbb

Please sign in to comment.