From 4cce9cb6397af70498525c7b1cc829de2b21edc9 Mon Sep 17 00:00:00 2001 From: Jason Miller Date: Tue, 22 Jun 2021 18:21:48 -0400 Subject: Add support for mitt.off("type"), which removes all handlers of a given type --- src/index.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/index.ts b/src/index.ts index 4648156..dfc0c1f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -59,8 +59,10 @@ export default function mitt>( */ on(type: Key, handler: GenericEventHandler) { const handlers: Array | undefined = all!.get(type); - const added = handlers && handlers.push(handler); - if (!added) { + if (handlers) { + handlers.push(handler); + } + else { all!.set(type, [handler] as EventHandlerList); } }, @@ -79,7 +81,7 @@ export default function mitt>( handlers.splice(handlers.indexOf(handler) >>> 0, 1); } else { - all.delete(type); + all!.set(type, []); } } }, -- cgit v1.2.3