From aa9ae241f8279ba7942e4e4eda1d4d9a56546faa Mon Sep 17 00:00:00 2001 From: Jason Miller Date: Fri, 14 Apr 2017 19:33:27 -0400 Subject: [PATCH] Avoid creating a new listener type array in `off()`, saves another 4 bytes (187b -> 183b) --- src/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 78d675d..9746b8d 100644 --- a/src/index.js +++ b/src/index.js @@ -36,8 +36,9 @@ export default function mitt(all: EventHandlerMap) { * @memberOf mitt */ off(type: string, handler: EventHandler) { - let e = all[type] || (all[type] = []); - e.splice(e.indexOf(handler) >>> 0, 1); + if (all[type]) { + all[type].splice(all[type].indexOf(handler) >>> 0, 1); + } }, /**