Skip to content
Myr

README.md

This file

Path

README.md

165 lines · 5.2 KiB · Markdown

Last changed by

codesponsor.ioJason Millerbefore adoption8b698fd

History of this file

Take it

Spruce up the readme 🌲Jason Millerbefore adoption44362fe

line 1why, one step back
1<p align="center">

Merge branch 'master' into refactorJason Millerbefore adoption4799316

line 2why, one step back
2 <img src="https://i.imgur.com/BqsX9NT.png" width="300" height="300" alt="mitt">

Spruce up the readme 🌲Jason Millerbefore adoption44362fe

line 3why, one step back
3 <br>

Merge branch 'master' into refactorJason Millerbefore adoption4799316

line 4why, one step back
4 <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 5why, one step back
5</p>

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 6
6

Merge branch 'master' into refactorJason Millerbefore adoption4799316

line 7why, one step back
7# Mitt

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 8
8

Merge branch 'master' into refactorJason Millerbefore adoption4799316

lines 9–10why, one step back
9> Tiny 200b functional event emitter / pubsub.
10

readme, re-run build processtunnckoCorebefore adoption19a32dc

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

Merge branch 'master' into refactorJason Millerbefore adoption4799316

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

Add a design note, hopefully addressing #10 👍Jason Millerbefore adoption0d51fe3

line 18why, one step back
18

codesponsor.ioJason Millerbefore adoption8b698fd

lines 19–22why, one step back
19<a target='_blank' rel='nofollow' href='https://app.codesponsor.io/link/WbARjbDRQz5y3N6VBEMPU4LW/developit/mitt'>
20 <img alt='Sponsor' width='888' height='68' src='https://app.codesponsor.io/embed/WbARjbDRQz5y3N6VBEMPU4LW/developit/mitt.svg' />21</a>22

Merge branch 'master' into refactorJason Millerbefore adoption4799316

line 23why, one step back
23## Table of Contents

resolve readme conflicttunnckoCorebefore adoptione361ab5

line 24why, one step back
24

Update docs.Jason Millerbefore adoption07f8819

lines 25–31why, one step back
25- [Install](#install)
26- [Usage](#usage)27- [Examples & Demos](#examples--demos)28- [API](#api)29- [Contribute](#contribute)30- [License](#license)31

Merge branch 'master' into refactorJason Millerbefore adoption4799316

line 32why, one step back
32## Install

resolve readme conflicttunnckoCorebefore adoptione361ab5

line 33why, one step back
33

Merge branch 'master' into refactorJason Millerbefore adoption4799316

line 34why, one step back
34This project uses [node](http://nodejs.org) and [npm](https://npmjs.com). Go check them out if you don't have them locally installed.

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 35
35

Merge branch 'master' into refactorJason Millerbefore adoption4799316

lines 36–38why, one step back
36```sh
37$ npm install --save mitt38```

Spruce up the readme 🌲Jason Millerbefore adoption44362fe

line 39why, one step back
39

Merge branch 'master' into refactorJason Millerbefore adoption4799316

line 40why, one step back
40Then with a module bundler like [rollup](http://rollupjs.org/) or [webpack](https://webpack.js.org/), use as you would anything else:

Spruce up the readme 🌲Jason Millerbefore adoption44362fe

line 41why, one step back
41

Merge branch 'master' into refactorJason Millerbefore adoption4799316

lines 42–54why, one step back
42```javascript
43// using ES6 modules44import mitt from 'mitt'4546// using CommonJS modules47var mitt = require('mitt')48```4950The [UMD](https://github.com/umdjs/umd) build is also available on [unpkg](https://unpkg.com):5152```html53<script src="https://unpkg.com/mitt/dist/mitt.umd.js"></script>54```

Update docs.Jason Millerbefore adoption07f8819

line 55why, one step back
55

Merge branch 'master' into refactorJason Millerbefore adoption4799316

lines 56–59why, one step back
56You can find the library on `window.mitt`.
5758## Usage59

Spruce up the readme 🌲Jason Millerbefore adoption44362fe

lines 60–77why, one step back
60```js
61import mitt from 'mitt'6263let emitter = mitt()6465// listen to an event66emitter.on('foo', e => console.log('foo', e) )6768// listen to all events69emitter.on('*', (type, e) => console.log(type, e) )7071// fire an event72emitter.emit('foo', { a: 'b' })7374// working with handler references:75function onFoo() {}76emitter.on('foo', onFoo) // listen77emitter.off('foo', onFoo) // unlisten

Initial commit! 🚀Jason Millerbefore adoptione77a42c

lines 78–79
78```
79

Typescript definitions (#25)Severinbefore adoptiond63b350

line 80why, one step back
80### Typescript

1.1.0Jason Millerbefore adoptionf147246

line 81why, one step back
81

Typescript definitions (#25)Severinbefore adoptiond63b350

lines 82–86why, one step back
82```ts
83import * as mitt from 'mitt';84let emitter: mitt.Emitter = new mitt();85```86

Merge branch 'master' into refactorJason Millerbefore adoption4799316

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

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 88
88

Merge branch 'master' into refactorJason Millerbefore adoption4799316

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

Typescript definitions (#25)Severinbefore adoptiond63b350

lines 94–95why, one step back
94
95* * *

Merge branch 'master' into refactorJason Millerbefore adoption4799316

line 96why, one step back
96

Initial commit! 🚀Jason Millerbefore adoptione77a42c

lines 97–102
97## API
9899### mitt100101Mitt: Tiny (~200b) functional event emitter / pubsub.102

Update docs.Jason Millerbefore adoption07f8819

line 103why, one step back
103Returns **Mitt**

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 104
104

refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9

line 105why, one step back
105#### emit

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 106
106

refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9

line 107why, one step back
107Invoke all handlers for the given type.

Change description for emit (fix #49) (#50)Denis Sikulerbefore adoptioncf764a1

line 108why, one step back
108If present, `"*"` handlers are invoked after type-matched handlers.

refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9

lines 109–112why, one step back
109
110**Parameters**111112- `type` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The event type to invoke

remove "drop support for emitting multiple args" thing as per https://github.com/developit/mitt/pull/19#issuecomment-273344689tunnckoCorebefore adoptionf4c60f4

line 113why, one step back
113- `evt` **\[Any]** Any value (object is recommended and powerful), passed to each handler

refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9

lines 114–116why, one step back
114
115### on116

Initial commit! 🚀Jason Millerbefore adoptione77a42c

lines 117–121
117Register an event handler for the given type.
118119**Parameters**120121- `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

refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9

line 122why, one step back
122- `handler` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** Function to call in response to given event

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 123
123

refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9

lines 124–125why, one step back
124### off
125

Initial commit! 🚀Jason Millerbefore adoptione77a42c

lines 126–131
126Remove an event handler for the given type.
127128**Parameters**129130- `type` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Type of event to unregister `handler` from, or `"*"`131- `handler` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** Handler function to remove

Merge branch 'master' into refactorJason Millerbefore adoption4799316

lines 132–133why, one step back
132
133## Contribute

Update docs.Jason Millerbefore adoption07f8819

line 134why, one step back
134

Merge branch 'master' into refactorJason Millerbefore adoption4799316

lines 135–137why, one step back
135First off, thanks for taking the time to contribute!
136Now, take a moment to be sure your contributions make sense to everyone else.137

Add Standard Version for Semantic Releases (#43)Abhi Aiyerbefore adoptiond728e90

lines 138–143why, one step back
138Development Start:
139140This project is typed with Flow Type annotations. To ensure you have the proper typings for this project run141142`flow-typed install`143

Merge branch 'master' into refactorJason Millerbefore adoption4799316

line 144why, one step back
144### Reporting Issues

Update docs.Jason Millerbefore adoption07f8819

line 145why, one step back
145

Merge branch 'master' into refactorJason Millerbefore adoption4799316

lines 146–149why, one step back
146Found a problem? Want a new feature? First of all see if your issue or idea has [already been reported](../../issues).
147If don't, just open a [new clear and descriptive issue](../../issues/new).148149### Submitting pull requests

Update docs.Jason Millerbefore adoption07f8819

line 150why, one step back
150

Merge branch 'master' into refactorJason Millerbefore adoption4799316

lines 151–152why, one step back
151Pull requests are the greatest contributions, so be sure they are focused in scope, and do avoid unrelated commits.
152

Update docs.Jason Millerbefore adoption07f8819

lines 153–161why, one step back
153- Fork it!
154- Clone your fork: `git clone https://github.com/<your-username>/mitt`155- Navigate to the newly cloned directory: `cd mitt`156- Create a new branch for the new feature: `git checkout -b my-new-feature`157- Install the tools necessary for development: `npm install`158- Make your changes.159- Commit your changes: `git commit -am 'Add some feature'`160- Push to the branch: `git push origin my-new-feature`161- Submit a pull request with full remarks documenting your changes.

Merge branch 'master' into refactorJason Millerbefore adoption4799316

lines 162–164why, one step back
162
163## License164

Update docs.Jason Millerbefore adoption07f8819

line 165why, one step back
165[MIT License](LICENSE.md) © [Jason Miller](https://jasonformat.com/)