Skip to content
Myr

README.md

This file

Path

README.md

161 lines · 4.9 KiB · Markdown

Last changed by

remove CodeSponsor (#68)Daniel Rufbefore adoptionb7276db

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

Merge branch 'master' into refactorJason Millerbefore adoption4799316

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

resolve readme conflicttunnckoCorebefore adoptione361ab5

line 20why, one step back
20

Update docs.Jason Millerbefore adoption07f8819

lines 21–27why, one step back
21- [Install](#install)
22- [Usage](#usage)23- [Examples & Demos](#examples--demos)24- [API](#api)25- [Contribute](#contribute)26- [License](#license)27

Merge branch 'master' into refactorJason Millerbefore adoption4799316

line 28why, one step back
28## Install

resolve readme conflicttunnckoCorebefore adoptione361ab5

line 29why, one step back
29

Merge branch 'master' into refactorJason Millerbefore adoption4799316

line 30why, one step back
30This 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 31
31

Merge branch 'master' into refactorJason Millerbefore adoption4799316

lines 32–34why, one step back
32```sh
33$ npm install --save mitt34```

Spruce up the readme 🌲Jason Millerbefore adoption44362fe

line 35why, one step back
35

Merge branch 'master' into refactorJason Millerbefore adoption4799316

line 36why, one step back
36Then 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 37why, one step back
37

Merge branch 'master' into refactorJason Millerbefore adoption4799316

lines 38–50why, one step back
38```javascript
39// using ES6 modules40import mitt from 'mitt'4142// using CommonJS modules43var mitt = require('mitt')44```4546The [UMD](https://github.com/umdjs/umd) build is also available on [unpkg](https://unpkg.com):4748```html49<script src="https://unpkg.com/mitt/dist/mitt.umd.js"></script>50```

Update docs.Jason Millerbefore adoption07f8819

line 51why, one step back
51

Merge branch 'master' into refactorJason Millerbefore adoption4799316

lines 52–55why, one step back
52You can find the library on `window.mitt`.
5354## Usage55

Spruce up the readme 🌲Jason Millerbefore adoption44362fe

lines 56–73why, one step back
56```js
57import mitt from 'mitt'5859let emitter = mitt()6061// listen to an event62emitter.on('foo', e => console.log('foo', e) )6364// listen to all events65emitter.on('*', (type, e) => console.log(type, e) )6667// fire an event68emitter.emit('foo', { a: 'b' })6970// working with handler references:71function onFoo() {}72emitter.on('foo', onFoo) // listen73emitter.off('foo', onFoo) // unlisten

Initial commit! 🚀Jason Millerbefore adoptione77a42c

lines 74–75
74```
75

Typescript definitions (#25)Severinbefore adoptiond63b350

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

1.1.0Jason Millerbefore adoptionf147246

line 77why, one step back
77

Typescript definitions (#25)Severinbefore adoptiond63b350

lines 78–82why, one step back
78```ts
79import * as mitt from 'mitt';80let emitter: mitt.Emitter = new mitt();81```82

Merge branch 'master' into refactorJason Millerbefore adoption4799316

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

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 84
84

Merge branch 'master' into refactorJason Millerbefore adoption4799316

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

Typescript definitions (#25)Severinbefore adoptiond63b350

lines 90–91why, one step back
90
91* * *

Merge branch 'master' into refactorJason Millerbefore adoption4799316

line 92why, one step back
92

Initial commit! 🚀Jason Millerbefore adoptione77a42c

lines 93–98
93## API
9495### mitt9697Mitt: Tiny (~200b) functional event emitter / pubsub.98

Update docs.Jason Millerbefore adoption07f8819

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

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 100
100

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

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

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 102
102

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

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

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

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

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

lines 105–108why, one step back
105
106**Parameters**107108- `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 109why, one step back
109- `evt` **\[Any]** Any value (object is recommended and powerful), passed to each handler

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

lines 110–112why, one step back
110
111### on112

Initial commit! 🚀Jason Millerbefore adoptione77a42c

lines 113–117
113Register an event handler for the given type.
114115**Parameters**116117- `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 118why, one step back
118- `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 119
119

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

lines 120–121why, one step back
120### off
121

Initial commit! 🚀Jason Millerbefore adoptione77a42c

lines 122–127
122Remove an event handler for the given type.
123124**Parameters**125126- `type` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Type of event to unregister `handler` from, or `"*"`127- `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 128–129why, one step back
128
129## Contribute

Update docs.Jason Millerbefore adoption07f8819

line 130why, one step back
130

Merge branch 'master' into refactorJason Millerbefore adoption4799316

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

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

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

Merge branch 'master' into refactorJason Millerbefore adoption4799316

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

Update docs.Jason Millerbefore adoption07f8819

line 141why, one step back
141

Merge branch 'master' into refactorJason Millerbefore adoption4799316

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

Update docs.Jason Millerbefore adoption07f8819

line 146why, one step back
146

Merge branch 'master' into refactorJason Millerbefore adoption4799316

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

Update docs.Jason Millerbefore adoption07f8819

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

Merge branch 'master' into refactorJason Millerbefore adoption4799316

lines 158–160why, one step back
158
159## License160

Update docs.Jason Millerbefore adoption07f8819

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