From 927a52bb10a09ab0ea9391644257aadda7d62d37 Mon Sep 17 00:00:00 2001 From: Dahan Gong Date: Fri, 13 Jan 2017 19:23:37 +0800 Subject: [PATCH] allow Eventable.off to remove a group of listeners It may do this when the argument `listener` is `undefined`. --- src/Eventable.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Eventable.js b/src/Eventable.js index cb3433f4d..d6d584f30 100644 --- a/src/Eventable.js +++ b/src/Eventable.js @@ -36,7 +36,7 @@ class Eventable { on (eventType, listener) { // if this type of event was never bound - if (!(eventType in this)) { + if (this[eventType]) { this[eventType] = [listener]; } else { @@ -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; } } }