Skip to content
Myr

README.md

This file

Path

README.md

89 lines · 2.9 KiB · Markdown

Last changed by

Add dependency status badge (#33)Thiago Santosbefore adoption9ffbcdc

History of this file

Take it

Spruce up the readme 🌲Jason Millerbefore adoption44362fe

lines 1–5why, one step back
1<p align="center">
2 <img src="https://i.imgur.com/BqsX9NT.png" width="256" height="256" alt="mitt">3 <br>4 <b>Mitt</b>: tiny 200b functional event emitter / pubsub.5 <br>

Add dependency status badge (#33)Thiago Santosbefore adoption9ffbcdc

line 6why, one step back
6 <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> <a href="https://david-dm.org/developit/mitt"><img src="https://david-dm.org/developit/mitt/status.svg" alt="dependencies Status"></a>

Spruce up the readme 🌲Jason Millerbefore adoption44362fe

line 7why, one step back
7</p>

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 8
8

Spruce up the readme 🌲Jason Millerbefore adoption44362fe

line 9why, one step back
9## Why Mitt?

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 10
10

1.0.1Jason Millerbefore adoptionafb0bff

lines 11–15why, one step back
11- **Microscopic:** weighs less than 200 bytes gzipped
12- **Useful:** a wildcard `"*"` event type listens to all events13- **Familiar:** same names & ideas as [Node's EventEmitter](https://nodejs.org/api/events.html#events_class_eventemitter)14- **Functional:** methods don't rely on `this`15- **Great Name:** somehow [mitt](https://npm.im/mitt) wasn't taken

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 16
16

Add demo, change support to IE9+Jason Millerbefore adoption84642dd

line 17why, one step back
17> Mitt was made for the browser, but works in any JavaScript runtime. It has no dependencies and supports IE9+.

Spruce up the readme 🌲Jason Millerbefore adoption44362fe

line 18why, one step back
18

Add demo, change support to IE9+Jason Millerbefore adoption84642dd

line 19why, one step back
19## Examples & Demos

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 20
20

Update README.mdJason Millerbefore adoption5f5367b

lines 21–25why, one step back
21<a href="http://codepen.io/developit/pen/rjMEwW?editors=0110">
22 <b>Preact + Mitt Codepen Demo</b>23 <br>24 <img src="https://i.imgur.com/CjBgOfJ.png" width="278" alt="preact + mitt preview">25</a>

Add demo, change support to IE9+Jason Millerbefore adoption84642dd

lines 26–27why, one step back
26
27* * *

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 28
28

Spruce up the readme 🌲Jason Millerbefore adoption44362fe

lines 29–50why, one step back
29## Usage
3031After installing via `npm install --save mitt`:3233```js34import mitt from 'mitt'3536let emitter = mitt()3738// listen to an event39emitter.on('foo', e => console.log('foo', e) )4041// listen to all events42emitter.on('*', (type, e) => console.log(type, e) )4344// fire an event45emitter.emit('foo', { a: 'b' })4647// working with handler references:48function onFoo() {}49emitter.on('foo', onFoo) // listen50emitter.off('foo', onFoo) // unlisten

Initial commit! 🚀Jason Millerbefore adoptione77a42c

lines 51–89
51```
5253* * *5455## API5657### mitt5859Mitt: Tiny (~200b) functional event emitter / pubsub.6061Returns **Mitt** 6263#### on6465Register an event handler for the given type.6667**Parameters**6869- `type` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Type of event to listen for, or `"*"` for all events70- `handler` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** Function to call in response to the given event7172#### off7374Remove an event handler for the given type.7576**Parameters**7778- `type` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Type of event to unregister `handler` from, or `"*"`79- `handler` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** Handler function to remove8081#### emit8283Invoke all handlers for the given type.84If present, `"*"` handlers are invoked prior to type-matched handlers.8586**Parameters**8788- `type` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The event type to invoke89- `event` **\[Any]** An event object, passed to each handler