Skip to content
Myr

README.md

This file

Path

README.md

168 lines · 5.4 KiB · Markdown

Last changed by

Fixing TypeScript usage. Fixes #60 (#67)David Khourshidbefore adoption0f4e8f0

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>

Add badges for gzip size and install size (#75)Stevenbefore adoption820ac6a

lines 4–5why, 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> <a href="https://unpkg.com/mitt/dist/mitt.umd.js"><img src="http://img.badgesize.io/https://unpkg.com/mitt/dist/mitt.umd.js?compression=gzip" alt="gzip size"></a> <a href="https://packagephobia.now.sh/result?p=mitt"><img src="https://packagephobia.now.sh/badge?p=mitt" alt="install size"></a>
5

Spruce up the readme 🌲Jason Millerbefore adoption44362fe

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

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 7
7

Merge branch 'master' into refactorJason Millerbefore adoption4799316

line 8why, one step back
8# Mitt

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 9
9

Merge branch 'master' into refactorJason Millerbefore adoption4799316

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

readme, re-run build processtunnckoCorebefore adoption19a32dc

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

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 17
17

Merge branch 'master' into refactorJason Millerbefore adoption4799316

line 18why, one step back
18Mitt 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 19why, one step back
19

Merge branch 'master' into refactorJason Millerbefore adoption4799316

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

resolve readme conflicttunnckoCorebefore adoptione361ab5

line 21why, one step back
21

Update docs.Jason Millerbefore adoption07f8819

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

Merge branch 'master' into refactorJason Millerbefore adoption4799316

line 29why, one step back
29## Install

resolve readme conflicttunnckoCorebefore adoptione361ab5

line 30why, one step back
30

Merge branch 'master' into refactorJason Millerbefore adoption4799316

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

Merge branch 'master' into refactorJason Millerbefore adoption4799316

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

Spruce up the readme 🌲Jason Millerbefore adoption44362fe

line 36why, one step back
36

Merge branch 'master' into refactorJason Millerbefore adoption4799316

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

Merge branch 'master' into refactorJason Millerbefore adoption4799316

lines 39–51why, one step back
39```javascript
40// using ES6 modules41import mitt from 'mitt'4243// using CommonJS modules44var mitt = require('mitt')45```4647The [UMD](https://github.com/umdjs/umd) build is also available on [unpkg](https://unpkg.com):4849```html50<script src="https://unpkg.com/mitt/dist/mitt.umd.js"></script>51```

Update docs.Jason Millerbefore adoption07f8819

line 52why, one step back
52

Merge branch 'master' into refactorJason Millerbefore adoption4799316

lines 53–56why, one step back
53You can find the library on `window.mitt`.
5455## Usage56

Spruce up the readme 🌲Jason Millerbefore adoption44362fe

lines 57–59why, one step back
57```js
58import mitt from 'mitt'59

Fixing TypeScript usage. Fixes #60 (#67)David Khourshidbefore adoption0f4e8f0

line 60why, one step back
60const emitter = mitt()

Spruce up the readme 🌲Jason Millerbefore adoption44362fe

lines 61–74why, one step back
61
62// listen to an event63emitter.on('foo', e => console.log('foo', e) )6465// listen to all events66emitter.on('*', (type, e) => console.log(type, e) )6768// fire an event69emitter.emit('foo', { a: 'b' })7071// working with handler references:72function onFoo() {}73emitter.on('foo', onFoo) // listen74emitter.off('foo', onFoo) // unlisten

Initial commit! 🚀Jason Millerbefore adoptione77a42c

lines 75–76
75```
76

Typescript definitions (#25)Severinbefore adoptiond63b350

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

1.1.0Jason Millerbefore adoptionf147246

line 78why, one step back
78

Typescript definitions (#25)Severinbefore adoptiond63b350

line 79why, one step back
79```ts

Fixing TypeScript usage. Fixes #60 (#67)David Khourshidbefore adoption0f4e8f0

lines 80–81why, one step back
80import mitt from 'mitt';
81const emitter: mitt.Emitter = mitt();

Typescript definitions (#25)Severinbefore adoptiond63b350

lines 82–83why, one step back
82```
83

Merge branch 'master' into refactorJason Millerbefore adoption4799316

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

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 85
85

Merge branch 'master' into refactorJason Millerbefore adoption4799316

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

Typescript definitions (#25)Severinbefore adoptiond63b350

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

Merge branch 'master' into refactorJason Millerbefore adoption4799316

line 93why, one step back
93

Initial commit! 🚀Jason Millerbefore adoptione77a42c

lines 94–95
94## API
95

Docs update.Jason Millerbefore adoptiona0578b7

lines 96–97why, one step back
96<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
97

Initial commit! 🚀Jason Millerbefore adoptione77a42c

lines 98–101
98### mitt
99100Mitt: Tiny (~200b) functional event emitter / pubsub.101

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

lines 102–103why, one step back
102**Parameters**
103

Docs update.Jason Millerbefore adoptiona0578b7

line 104why, one step back
104- `all` **EventHandlerMap**

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

line 105why, one step back
105

Docs update.Jason Millerbefore adoptiona0578b7

lines 106–107why, one step back
106Returns **Mitt**
107

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

lines 108–109why, one step back
108### on
109

Initial commit! 🚀Jason Millerbefore adoptione77a42c

lines 110–113
110Register an event handler for the given type.
111112**Parameters**113

Docs update.Jason Millerbefore adoptiona0578b7

lines 114–115why, one step back
114- `type` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Type of event to listen for, or `"*"` for all events
115- `handler` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** Function to call in response to given event

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 116
116

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

lines 117–118why, one step back
117### off
118

Initial commit! 🚀Jason Millerbefore adoptione77a42c

lines 119–122
119Remove an event handler for the given type.
120121**Parameters**122

Docs update.Jason Millerbefore adoptiona0578b7

lines 123–134why, one step back
123- `type` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Type of event to unregister `handler` from, or `"*"`
124- `handler` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** Handler function to remove125126### emit127128Invoke all handlers for the given type.129If present, `"*"` handlers are invoked after type-matched handlers.130131**Parameters**132133- `type` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The event type to invoke134- `evt` **Any?** Any value (object is recommended and powerful), passed to each handler

Merge branch 'master' into refactorJason Millerbefore adoption4799316

lines 135–136why, one step back
135
136## Contribute

Update docs.Jason Millerbefore adoption07f8819

line 137why, one step back
137

Merge branch 'master' into refactorJason Millerbefore adoption4799316

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

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

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

Merge branch 'master' into refactorJason Millerbefore adoption4799316

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

Update docs.Jason Millerbefore adoption07f8819

line 148why, one step back
148

Merge branch 'master' into refactorJason Millerbefore adoption4799316

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

Update docs.Jason Millerbefore adoption07f8819

line 153why, one step back
153

Merge branch 'master' into refactorJason Millerbefore adoption4799316

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

Update docs.Jason Millerbefore adoption07f8819

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

Merge branch 'master' into refactorJason Millerbefore adoption4799316

lines 165–167why, one step back
165
166## License167

Clean up repo rootJason Millerbefore adoption4a8e0a5

line 168why, one step back
168[MIT License](https://opensource.org/licenses/MIT) © [Jason Miller](https://jasonformat.com/)