diff options
| author | tunnckoCore <[email protected]> | 2017-01-17 18:21:35 +0200 |
|---|---|---|
| committer | tunnckoCore <[email protected]> | 2017-01-17 18:21:35 +0200 |
| commit | a6190e91a68d35adffbeda2e92f92ec565557f89 (patch) | |
| tree | 3d92550834ee10c117ca195db96568f9762c95b1 /README.md | |
| parent | 42fb45ef29482c136e7ba602bc27bfe2c50c2f00 (diff) | |
refactor: fixes #2, #6, #12 and #13
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 45 |
1 files changed, 25 insertions, 20 deletions
@@ -6,21 +6,18 @@ <a href="https://www.npmjs.org/package/mitt"><img src="https://img.shields.io/npm/v/mitt.svg?style=flat" alt="npm"></a> <a href="https://travis-ci.org/developit/mitt"><img src="https://travis-ci.org/developit/mitt.svg?branch=master" alt="travis"></a> </p> - ## Why Mitt? -- **Microscopic:** weighs less than 200 bytes gzipped -- **Useful:** a wildcard `"*"` event type listens to all events -- **Familiar:** same names & ideas as [Node's EventEmitter](https://nodejs.org/api/events.html#events_class_eventemitter) -- **Functional:** methods don't rely on `this` -- **Great Name:** somehow [mitt](https://npm.im/mitt) wasn't taken +- **Microscopic:** weighs less than 200 bytes gzipped +- **Useful:** a wildcard `"*"` event type listens to all events +- **Familiar:** same names & ideas as [Node's EventEmitter](https://nodejs.org/api/events.html#events_class_eventemitter) +- **Functional:** methods don't rely on `this` +- **Great Name:** somehow [mitt](https://npm.im/mitt) wasn't taken > Mitt was made for the browser, but works in any JavaScript runtime. It has no dependencies and only uses basic language features. It probably works in Internet Explorer 5. - * * * - ## Usage After installing via `npm install --save mitt`: @@ -55,16 +52,32 @@ Mitt: Tiny (~200b) functional event emitter / pubsub. Returns **Mitt** -#### on +#### emit + +Invoke all handlers for the given type. +If present, `"*"` handlers are invoked prior to type-matched handlers. + +**Parameters** + +- `type` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The event type to invoke +- `arg1` **\[Any]** A value (first argument), passed to each handler +- `arg2` **\[Any]** A value (second argument), passed to each handler +- `arg3` **\[Any]** A value (third argument), passed to each handler + +Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** the `mitt` instance for chaining + +### on Register an event handler for the given type. **Parameters** - `type` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Type of event to listen for, or `"*"` for all events -- `handler` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** Function to call in response to the given event +- `handler` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** Function to call in response to given event + +Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** the `mitt` instance for chaining -#### off +### off Remove an event handler for the given type. @@ -73,12 +86,4 @@ Remove an event handler for the given type. - `type` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Type of event to unregister `handler` from, or `"*"` - `handler` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** Handler function to remove -#### emit - -Invoke all handlers for the given type. -If present, `"*"` handlers are invoked prior to type-matched handlers. - -**Parameters** - -- `type` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The event type to invoke -- `event` **\[Any]** An event object, passed to each handler +Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** the `mitt` instance for chaining |
