Skip to content

Commit 4517958

Browse files
tungvdevelopit
authored andcommitted
more precise type annotation for WildCardEventHandler (#58)
* more precise type annotation for WildCardEventHandler * fix: remove duplicated @flow * fix: make * optional
1 parent 10711eb commit 4517958

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
// @flow
22
// An event handler can take an optional event argument
33
// and should not return a value
4-
type EventHandler = (typeOrEvent?: string|any, event?: any) => void;
4+
type EventHandler = (event?: any) => void;
5+
type WildCardEventHandler = (type: string, event?: any) => void
6+
57
// An array of all currently registered event handlers for a type
68
type EventHandlerList = Array<EventHandler>;
9+
type WildCardEventHandlerList = Array<WildCardEventHandler>;
710
// A map of event types and their corresponding event handlers.
811
type EventHandlerMap = {
12+
'*'?: WildCardEventHandlerList,
913
[type: string]: EventHandlerList,
1014
};
1115

@@ -49,7 +53,7 @@ export default function mitt(all: EventHandlerMap) {
4953
* @param {Any} [evt] Any value (object is recommended and powerful), passed to each handler
5054
* @memberof mitt
5155
*/
52-
emit(type: string, evt?: any) {
56+
emit(type: string, evt: any) {
5357
(all[type] || []).map((handler) => { handler(evt); });
5458
(all['*'] || []).map((handler) => { handler(type, evt); });
5559
}

0 commit comments

Comments
 (0)