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; }