From 787edade99a535cd46f54ab05f32a83ccdb4656e Mon Sep 17 00:00:00 2001 From: milkmidi Date: Mon, 22 Apr 2024 16:23:45 +0800 Subject: [PATCH] feat: add unsub function form on --- src/index.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 17672aa..5b007e4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -51,7 +51,7 @@ export default function mitt>( | WildcardHandler; all = all || new Map(); - return { + const instance = { /** * A Map of event names to registered handler functions. */ @@ -70,6 +70,9 @@ export default function mitt>( } else { all!.set(type, [handler] as EventHandlerList); } + return () => { + instance.off(type, handler); + }; }, /** @@ -120,4 +123,5 @@ export default function mitt>( } } }; + return instance; }