aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsealice <[email protected]>2021-01-11 20:41:12 +0800
committersealice <[email protected]>2021-01-21 21:32:33 +0800
commit2d59261b75de2cbc4631ccee8db717911974467e (patch)
tree7b9cf7f502e87e4289b589418f05a30c74cfa589
parent22c5dcba10736aecb1f39ee88d9f85278108c988 (diff)
compression code
-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); });
}
};
}