diff --git a/src/index.ts b/src/index.ts index ae85607..9340fae 100644 --- a/src/index.ts +++ b/src/index.ts @@ -77,9 +77,12 @@ export default function mitt(all?: EventHandlerMap): Emitter { * @param {Any} [evt] Any value (object is recommended and powerful), passed to each handler * @memberOf mitt */ - emit(type: EventType, evt: T) { - ((all.get(type) || []) as EventHandlerList).slice().map((handler) => { handler(evt); }); - ((all.get('*') || []) as WildCardEventHandlerList).slice().map((handler) => { handler(type, evt); }); + emit(type: EventType, evt?: T) { + let handlers = all.get(type); + handlers && (handlers as EventHandlerList).slice().map((handler) => { handler(evt); }); + + handlers = all.get('*'); + handlers && (handlers as WildCardEventHandlerList).slice().map((handler) => { handler(type, evt); }); } }; }