File tree Expand file tree Collapse file tree 4 files changed +62
-1
lines changed
Expand file tree Collapse file tree 4 files changed +62
-1
lines changed Original file line number Diff line number Diff line change @@ -71,6 +71,12 @@ emitter.on('foo', onFoo) // listen
7171emitter .off (' foo' , onFoo) // unlisten
7272```
7373
74+ ### Typescript
75+ ``` ts
76+ import * as mitt from ' mitt' ;
77+ let emitter: mitt .Emitter = new mitt ();
78+ ```
79+
7480## Examples & Demos
7581
7682<a href =" http://codepen.io/developit/pen/rjMEwW?editors=0110 " >
@@ -79,6 +85,8 @@ emitter.off('foo', onFoo) // unlisten
7985 <img src =" https://i.imgur.com/CjBgOfJ.png " width =" 278 " alt =" preact + mitt preview " >
8086</a >
8187
88+ * * *
89+
8290## API
8391
8492### mitt
Original file line number Diff line number Diff line change 1+ declare var mitt : mitt . MittStatic ;
2+
3+ declare module "mitt" {
4+ export = mitt ;
5+ }
6+
7+ declare namespace mitt {
8+ type Handler = ( event ?: any ) => void ;
9+
10+ interface MittStatic {
11+ new ( all ?: { [ key : string ] : Handler } ) : Emitter ;
12+ }
13+
14+ interface Emitter {
15+ /**
16+ * Register an event handler for the given type.
17+ *
18+ * @param {string } type Type of event to listen for, or `"*"` for all events.
19+ * @param {Handler } handler Function to call in response to the given event.
20+ *
21+ * @memberOf Mitt
22+ */
23+ on ( type : string , handler : Handler ) : void ;
24+
25+ /**
26+ * Function to call in response to the given event
27+ *
28+ * @param {string } type Type of event to unregister `handler` from, or `"*"`
29+ * @param {Handler } handler Handler function to remove.
30+ *
31+ * @memberOf Mitt
32+ */
33+ off ( type : string , handler : Handler ) : void ;
34+
35+ /**
36+ * Invoke all handlers for the given type.
37+ * If present, `"*"` handlers are invoked prior to type-matched handlers.
38+ *
39+ * @param {string } type The event type to invoke
40+ * @param {any } [event] An event object, passed to each handler
41+ *
42+ * @memberOf Mitt
43+ */
44+ emit ( type : string , event ?: any ) : void ;
45+ }
46+ }
Original file line number Diff line number Diff line change 3131 "license" : " MIT" ,
3232 "files" : [
3333 " src" ,
34- " dist"
34+ " dist" ,
35+ " mitt.d.ts"
3536 ],
3637 "eslintConfig" : {
3738 "parser" : " babel-eslint" ,
4849 "semi" : [2 , " always" ]
4950 }
5051 },
52+ "typings" : " ./mitt.d.ts" ,
5153 "devDependencies" : {
5254 "babel-core" : " ^6.9.1" ,
5355 "babel-eslint" : " ^7.1.1" ,
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " mitt" ,
3+ "main" : " mitt.d.ts" ,
4+ "version" : false
5+ }
You can’t perform that action at this time.
0 commit comments