Skip to content

Commit

Permalink
allow Eventable.off to remove a group of listeners
Browse files Browse the repository at this point in the history
It may do this when the argument `listener` is `undefined`.
  • Loading branch information
gdh1995 committed Jan 13, 2017
1 parent 2f168c7 commit 9f0ae6d
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/Eventable.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ class Eventable {

on (eventType, listener) {
// if this type of event was never bound
if (!(eventType in this)) {
this[eventType] = [listener];
if (this[eventType]) {
this[eventType].push(listener);
}
else {
this[eventType].push(listener);
this[eventType] = [listener];
}
}

Expand All @@ -50,7 +50,11 @@ class Eventable {
const index = eventList? indexOf(eventList, listener) : -1;

if (index !== -1) {
this[eventType].splice(index, 1);
eventList.splice(index, 1);
}
let undef;
if (eventList && eventList.length === 0 || undef === listener) {
this[eventType] = undef;
}
}
}
Expand Down

0 comments on commit 9f0ae6d

Please sign in to comment.