Skip to content
Myr

README.md

This file

Path

README.md

180 lines · 5.6 KiB · Markdown

Last changed by

Fix the format and update the off APIsealicebefore adoptionec9122b

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>

update readme badgesJason Millerbefore adoption8d987a7

lines 4–6why, one step back
4 <a href="https://www.npmjs.org/package/mitt"><img src="https://img.shields.io/npm/v/mitt.svg" alt="npm"></a>
5 <img src="https://github.com/developit/mitt/workflows/CI/badge.svg" alt="build status">6 <a href="https://unpkg.com/mitt/dist/mitt.js"><img src="https://img.badgesize.io/https://unpkg.com/mitt/dist/mitt.js?compression=gzip" alt="gzip size"></a>

Spruce up the readme 🌲Jason Millerbefore adoption44362fe

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

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 8
8

Merge branch 'master' into refactorJason Millerbefore adoption4799316

line 9why, one step back
9# Mitt

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 10
10

Merge branch 'master' into refactorJason Millerbefore adoption4799316

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

readme, re-run build processtunnckoCorebefore adoption19a32dc

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

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 18
18

Merge branch 'master' into refactorJason Millerbefore adoption4799316

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

Merge branch 'master' into refactorJason Millerbefore adoption4799316

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

resolve readme conflicttunnckoCorebefore adoptione361ab5

line 22why, one step back
22

Update docs.Jason Millerbefore adoption07f8819

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

Merge branch 'master' into refactorJason Millerbefore adoption4799316

line 30why, one step back
30## Install

resolve readme conflicttunnckoCorebefore adoptione361ab5

line 31why, one step back
31

Merge branch 'master' into refactorJason Millerbefore adoption4799316

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

Merge branch 'master' into refactorJason Millerbefore adoption4799316

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

Spruce up the readme 🌲Jason Millerbefore adoption44362fe

line 37why, one step back
37

Merge branch 'master' into refactorJason Millerbefore adoption4799316

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

Merge branch 'master' into refactorJason Millerbefore adoption4799316

lines 40–52why, one step back
40```javascript
41// using ES6 modules42import mitt from 'mitt'4344// using CommonJS modules45var mitt = require('mitt')46```4748The [UMD](https://github.com/umdjs/umd) build is also available on [unpkg](https://unpkg.com):4950```html51<script src="https://unpkg.com/mitt/dist/mitt.umd.js"></script>52```

Update docs.Jason Millerbefore adoption07f8819

line 53why, one step back
53

Merge branch 'master' into refactorJason Millerbefore adoption4799316

lines 54–57why, one step back
54You can find the library on `window.mitt`.
5556## Usage57

Spruce up the readme 🌲Jason Millerbefore adoption44362fe

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

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

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

Spruce up the readme 🌲Jason Millerbefore adoption44362fe

lines 62–71why, one step back
62
63// listen to an event64emitter.on('foo', e => console.log('foo', e) )6566// listen to all events67emitter.on('*', (type, e) => console.log(type, e) )6869// fire an event70emitter.emit('foo', { a: 'b' })71

Merge branch 'expose-all' of https://github.com/jaylinski/mittJason Millerbefore adoption0f41ead

lines 72–74why, one step back
72// clearing all events
73emitter.all.clear()74

Spruce up the readme 🌲Jason Millerbefore adoption44362fe

lines 75–78why, one step back
75// working with handler references:
76function onFoo() {}77emitter.on('foo', onFoo) // listen78emitter.off('foo', onFoo) // unlisten

Initial commit! 🚀Jason Millerbefore adoptione77a42c

lines 79–80
79```
80

Typescript definitions (#25)Severinbefore adoptiond63b350

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

1.1.0Jason Millerbefore adoptionf147246

line 82why, one step back
82

Typescript definitions (#25)Severinbefore adoptiond63b350

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

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

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

Typescript definitions (#25)Severinbefore adoptiond63b350

lines 86–87why, one step back
86```
87

Merge branch 'master' into refactorJason Millerbefore adoption4799316

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

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 89
89

Merge branch 'master' into refactorJason Millerbefore adoption4799316

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

Typescript definitions (#25)Severinbefore adoptiond63b350

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

Merge branch 'master' into refactorJason Millerbefore adoption4799316

line 97why, one step back
97

Initial commit! 🚀Jason Millerbefore adoptione77a42c

lines 98–99
98## API
99

Docs update.Jason Millerbefore adoptiona0578b7

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

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

lines 102–104why, one step back
102#### Table of Contents
103104- [mitt](#mitt)

Merge branch 'expose-all' of https://github.com/jaylinski/mittJason Millerbefore adoption0f41ead

line 105why, one step back
105- [all](#all)

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

lines 106–112why, one step back
106- [on](#on)
107 - [Parameters](#parameters)108- [off](#off)109 - [Parameters](#parameters-1)110- [emit](#emit)111 - [Parameters](#parameters-2)112

Initial commit! 🚀Jason Millerbefore adoptione77a42c

lines 113–116
113### mitt
114115Mitt: Tiny (~200b) functional event emitter / pubsub.116

Add generic types and update tests (#107)Jack Franklinbefore adoption5116df4

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

Merge branch 'expose-all' of https://github.com/jaylinski/mittJason Millerbefore adoption0f41ead

lines 118–121why, one step back
118
119### all120121A Map of event names to registered handler functions.

Docs update.Jason Millerbefore adoptiona0578b7

line 122why, one step back
122

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

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

Initial commit! 🚀Jason Millerbefore adoptione77a42c

lines 125–126
125Register 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 listen for, or `"*"` for all events

Docs update.Jason Millerbefore adoptiona0578b7

line 130why, one step back
130- `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 131
131

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

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

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 134
134Remove an event handler for the given type.

Fix the format and update the off APIsealicebefore adoptionec9122b

line 135why, one step back
135If omit the `handler`, all event handlers of the given type are deleted.

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 136
136

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

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

Initial commit! 🚀Jason Millerbefore adoptione77a42c

line 138
138

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

line 139why, one step back
139- `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 140–146why, one step back
140- `handler` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** Handler function to remove
141142### emit143144Invoke all handlers for the given type.145If present, `"*"` handlers are invoked after type-matched handlers.146

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

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

Add note about manually firing "*" handlersJason Millerbefore adoptioncfd246c

line 148why, one step back
148

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

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

Docs update.Jason Millerbefore adoptiona0578b7

line 150why, one step back
150

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

line 151why, one step back
151- `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 152why, one step back
152- `evt` **Any?** Any value (object is recommended and powerful), passed to each handler

Merge branch 'master' into refactorJason Millerbefore adoption4799316

lines 153–154why, one step back
153
154## Contribute

Update docs.Jason Millerbefore adoption07f8819

line 155why, one step back
155

Merge branch 'master' into refactorJason Millerbefore adoption4799316

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

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

line 158why, one step back
158

Merge branch 'master' into refactorJason Millerbefore adoption4799316

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

Update docs.Jason Millerbefore adoption07f8819

line 160why, one step back
160

Merge branch 'master' into refactorJason Millerbefore adoption4799316

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

Update docs.Jason Millerbefore adoption07f8819

line 165why, one step back
165

Merge branch 'master' into refactorJason Millerbefore adoption4799316

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

Update docs.Jason Millerbefore adoption07f8819

lines 168–176why, one step back
168- Fork it!
169- Clone your fork: `git clone https://github.com/<your-username>/mitt`170- Navigate to the newly cloned directory: `cd mitt`171- Create a new branch for the new feature: `git checkout -b my-new-feature`172- Install the tools necessary for development: `npm install`173- Make your changes.174- Commit your changes: `git commit -am 'Add some feature'`175- Push to the branch: `git push origin my-new-feature`176- Submit a pull request with full remarks documenting your changes.

Merge branch 'master' into refactorJason Millerbefore adoption4799316

lines 177–179why, one step back
177
178## License179

Clean up repo rootJason Millerbefore adoption4a8e0a5

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