Skip to content

Commit 7872a47

Browse files
committed
Merge branch 'cheaper' of https://github.com/sealice/mitt into sealice-cheaper
2 parents 8f439b8 + 2d59261 commit 7872a47

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

src/index.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,23 @@ export default function mitt<Events extends Record<EventType, unknown>>(
8989
* @memberOf mitt
9090
*/
9191
emit<Key extends keyof Events>(type: Key, evt?: Events[Key]) {
92-
((all!.get(type) || []) as EventHandlerList<Events[keyof Events]>)
93-
.slice()
94-
.map((handler) => {
95-
handler(evt!);
96-
});
97-
((all!.get('*') || []) as WildCardEventHandlerList<Events>)
98-
.slice()
99-
.map((handler) => {
100-
handler(type, evt!);
101-
});
92+
let handlers = all!.get(type);
93+
if (handlers) {
94+
(handlers as EventHandlerList<Events[keyof Events]>)
95+
.slice()
96+
.map((handler) => {
97+
handler(evt!);
98+
});
99+
}
100+
101+
handlers = all!.get('*');
102+
if (handlers) {
103+
(handlers as WildCardEventHandlerList<Events>)
104+
.slice()
105+
.map((handler) => {
106+
handler(type, evt!);
107+
});
108+
}
102109
}
103110
};
104111
}

0 commit comments

Comments
 (0)