aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/index.ts9
1 files changed, 6 insertions, 3 deletions
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<T = any>(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<T = any>(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); });
}
};
}