diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/index.ts | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/src/index.ts b/src/index.ts index 00286bc..5365b6e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -89,16 +89,23 @@ export default function mitt<Events extends Record<EventType, unknown>>( * @memberOf mitt */ emit<Key extends keyof Events>(type: Key, evt?: Events[Key]) { - ((all!.get(type) || []) as EventHandlerList<Events[keyof Events]>) - .slice() - .map((handler) => { - handler(evt!); - }); - ((all!.get('*') || []) as WildCardEventHandlerList<Events>) - .slice() - .map((handler) => { - handler(type, evt!); - }); + let handlers = all!.get(type); + if (handlers) { + (handlers as EventHandlerList<Events[keyof Events]>) + .slice() + .map((handler) => { + handler(evt!); + }); + } + + handlers = all!.get('*'); + if (handlers) { + (handlers as WildCardEventHandlerList<Events>) + .slice() + .map((handler) => { + handler(type, evt!); + }); + } } }; } |
