README.md
This file
Path
README.md
165 lines · 5.2 KiB · Markdown
Last changed by
codesponsor.ioJason Millerbefore adoption8b698fd
History of this fileTake it
Spruce up the readme 🌲Jason Millerbefore adoption44362fe
line 1why, one step back1<p align="center">Merge branch 'master' into refactorJason Millerbefore adoption4799316
line 2why, one step back2 <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 back3 <br>Merge branch 'master' into refactorJason Millerbefore adoption4799316
line 4why, one step back4 <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 back5</p>6Merge branch 'master' into refactorJason Millerbefore adoption4799316
line 7why, one step back7# Mitt8Merge branch 'master' into refactorJason Millerbefore adoption4799316
lines 9–10why, one step back9> Tiny 200b functional event emitter / pubsub.10readme, re-run build processtunnckoCorebefore adoption19a32dc
lines 11–15why, one step back11- **Microscopic:** weighs less than 200 bytes gzipped12- **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 taken16Merge branch 'master' into refactorJason Millerbefore adoption4799316
line 17why, one step back17Mitt 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 back18codesponsor.ioJason Millerbefore adoption8b698fd
lines 19–22why, one step back19<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>22Merge branch 'master' into refactorJason Millerbefore adoption4799316
line 23why, one step back23## Table of Contentsresolve readme conflicttunnckoCorebefore adoptione361ab5
line 24why, one step back24Update docs.Jason Millerbefore adoption07f8819
lines 25–31why, one step back25- [Install](#install)26- [Usage](#usage)27- [Examples & Demos](#examples--demos)28- [API](#api)29- [Contribute](#contribute)30- [License](#license)31Merge branch 'master' into refactorJason Millerbefore adoption4799316
line 32why, one step back32## Installresolve readme conflicttunnckoCorebefore adoptione361ab5
line 33why, one step back33Merge branch 'master' into refactorJason Millerbefore adoption4799316
line 34why, one step back34This project uses [node](http://nodejs.org) and [npm](https://npmjs.com). Go check them out if you don't have them locally installed.35Merge branch 'master' into refactorJason Millerbefore adoption4799316
lines 36–38why, one step back36```sh37$ npm install --save mitt38```Spruce up the readme 🌲Jason Millerbefore adoption44362fe
line 39why, one step back39Merge branch 'master' into refactorJason Millerbefore adoption4799316
line 40why, one step back40Then 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 back41Merge branch 'master' into refactorJason Millerbefore adoption4799316
lines 42–54why, one step back42```javascript43// 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 back55Merge branch 'master' into refactorJason Millerbefore adoption4799316
lines 56–59why, one step back56You can find the library on `window.mitt`.5758## Usage59Spruce up the readme 🌲Jason Millerbefore adoption44362fe
lines 60–77why, one step back60```js61import 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) // unlistenInitial commit! 🚀Jason Millerbefore adoptione77a42c
lines 78–7978```79Typescript definitions (#25)Severinbefore adoptiond63b350
line 80why, one step back80### Typescript1.1.0Jason Millerbefore adoptionf147246
line 81why, one step back81Typescript definitions (#25)Severinbefore adoptiond63b350
lines 82–86why, one step back82```ts83import * as mitt from 'mitt';84let emitter: mitt.Emitter = new mitt();85```86Merge branch 'master' into refactorJason Millerbefore adoption4799316
line 87why, one step back87## Examples & Demos88Merge branch 'master' into refactorJason Millerbefore adoption4799316
lines 89–93why, one step back89<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 back9495* * *Merge branch 'master' into refactorJason Millerbefore adoption4799316
line 96why, one step back96Initial commit! 🚀Jason Millerbefore adoptione77a42c
lines 97–10297## API9899### mitt100101Mitt: Tiny (~200b) functional event emitter / pubsub.102Update docs.Jason Millerbefore adoption07f8819
line 103why, one step back103Returns **Mitt** 104refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 105why, one step back105#### emit106refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 107why, one step back107Invoke all handlers for the given type.Change description for emit (fix #49) (#50)Denis Sikulerbefore adoptioncf764a1
line 108why, one step back108If present, `"*"` handlers are invoked after type-matched handlers.refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 109–112why, one step back109110**Parameters**111112- `type` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The event type to invokeremove "drop support for emitting multiple args" thing as per https://github.com/developit/mitt/pull/19#issuecomment-273344689tunnckoCorebefore adoptionf4c60f4
line 113why, one step back113- `evt` **\[Any]** Any value (object is recommended and powerful), passed to each handlerrefactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 114–116why, one step back114115### on116Initial commit! 🚀Jason Millerbefore adoptione77a42c
lines 117–121117Register 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 eventsrefactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 122why, one step back122- `handler` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** Function to call in response to given event123refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 124–125why, one step back124### off125Initial commit! 🚀Jason Millerbefore adoptione77a42c
lines 126–131126Remove 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 removeMerge branch 'master' into refactorJason Millerbefore adoption4799316
lines 132–133why, one step back132133## ContributeUpdate docs.Jason Millerbefore adoption07f8819
line 134why, one step back134Merge branch 'master' into refactorJason Millerbefore adoption4799316
lines 135–137why, one step back135First off, thanks for taking the time to contribute!136Now, take a moment to be sure your contributions make sense to everyone else.137Add Standard Version for Semantic Releases (#43)Abhi Aiyerbefore adoptiond728e90
lines 138–143why, one step back138Development Start:139140This project is typed with Flow Type annotations. To ensure you have the proper typings for this project run141142`flow-typed install`143Merge branch 'master' into refactorJason Millerbefore adoption4799316
line 144why, one step back144### Reporting IssuesUpdate docs.Jason Millerbefore adoption07f8819
line 145why, one step back145Merge branch 'master' into refactorJason Millerbefore adoption4799316
lines 146–149why, one step back146Found 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 requestsUpdate docs.Jason Millerbefore adoption07f8819
line 150why, one step back150Merge branch 'master' into refactorJason Millerbefore adoption4799316
lines 151–152why, one step back151Pull requests are the greatest contributions, so be sure they are focused in scope, and do avoid unrelated commits.152Update docs.Jason Millerbefore adoption07f8819
lines 153–161why, one step back153- 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 back162163## License164Update docs.Jason Millerbefore adoption07f8819
line 165why, one step back165[MIT License](LICENSE.md) © [Jason Miller](https://jasonformat.com/)