Skip to content
Myr

README.md

This file

Path

README.md

170 lines · 5.4 KiB · Markdown

Last changed by

Merge branch 'master' of github.com:developit/mittJason Millerbefore adoptionc36df69

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' of github.com:developit/mittJason Millerbefore adoptionc36df69

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://unpkg.com/mitt/dist/mitt.umd.js"><img src="http://img.badgesize.io/https://unpkg.com/mitt/dist/mitt.js?compression=gzip" alt="gzip size"></a>

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

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

Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f

lines 98–107why, one step back
98#### Table of Contents
99100- [mitt](#mitt)101- [on](#on)102 - [Parameters](#parameters)103- [off](#off)104 - [Parameters](#parameters-1)105- [emit](#emit)106 - [Parameters](#parameters-2)107

Initial commit! 🚀Jason Millerbefore adoptione77a42c

lines 108–111
108### mitt
109110Mitt: Tiny (~200b) functional event emitter / pubsub.111

Docs update.Jason Millerbefore adoptiona0578b7

lines 112–113why, one step back
112Returns **Mitt**
113

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

lines 114–115why, one step back
114### on
115

Initial commit! 🚀Jason Millerbefore adoptione77a42c

lines 116–117
116Register an event handler for the given type.
117

Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f

line 118why, one step back
118#### Parameters

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 119
119

Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f

line 120why, one step back
120- `type` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [symbol](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Symbol))** Type of event to listen for, or `"*"` for all events

Docs update.Jason Millerbefore adoptiona0578b7

line 121why, one step back
121- `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 122
122

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

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

Initial commit! 🚀Jason Millerbefore adoptione77a42c

lines 125–126
125Remove an event handler for the given type.
126

Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f

line 127why, one step back
127#### Parameters

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 128
128

Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f

line 129why, one step back
129- `type` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [symbol](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Symbol))** Type of event to unregister `handler` from, or `"*"`

Docs update.Jason Millerbefore adoptiona0578b7

lines 130–136why, one step back
130- `handler` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** Handler function to remove
131132### emit133134Invoke all handlers for the given type.135If present, `"*"` handlers are invoked after type-matched handlers.136

Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f

line 137why, one step back
137Note: Manually firing "\*" handlers is not supported.

Add note about manually firing "*" handlersJason Millerbefore adoptioncfd246c

line 138why, one step back
138

Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f

line 139why, one step back
139#### Parameters

Docs update.Jason Millerbefore adoptiona0578b7

line 140why, one step back
140

Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f

line 141why, one step back
141- `type` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [symbol](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Symbol))** The event type to invoke

Docs update.Jason Millerbefore adoptiona0578b7

line 142why, one step back
142- `evt` **Any?** Any value (object is recommended and powerful), passed to each handler

Merge branch 'master' into refactorJason Millerbefore adoption4799316

lines 143–144why, one step back
143
144## Contribute

Update docs.Jason Millerbefore adoption07f8819

line 145why, one step back
145

Merge branch 'master' into refactorJason Millerbefore adoption4799316

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

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

line 148why, one step back
148

Merge branch 'master' into refactorJason Millerbefore adoption4799316

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

Update docs.Jason Millerbefore adoption07f8819

line 150why, one step back
150

Merge branch 'master' into refactorJason Millerbefore adoption4799316

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

Update docs.Jason Millerbefore adoption07f8819

line 155why, one step back
155

Merge branch 'master' into refactorJason Millerbefore adoption4799316

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

Update docs.Jason Millerbefore adoption07f8819

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

Merge branch 'master' into refactorJason Millerbefore adoption4799316

lines 167–169why, one step back
167
168## License169

Clean up repo rootJason Millerbefore adoption4a8e0a5

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