README.md
This file
Path
README.md
167 lines · 5.1 KiB · Markdown
Last changed by
Docs update.Jason Millerbefore adoptiona0578b7
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 back18Merge branch 'master' into refactorJason Millerbefore adoption4799316
line 19why, one step back19## Table of Contentsresolve readme conflicttunnckoCorebefore adoptione361ab5
line 20why, one step back20Update docs.Jason Millerbefore adoption07f8819
lines 21–27why, one step back21- [Install](#install)22- [Usage](#usage)23- [Examples & Demos](#examples--demos)24- [API](#api)25- [Contribute](#contribute)26- [License](#license)27Merge branch 'master' into refactorJason Millerbefore adoption4799316
line 28why, one step back28## Installresolve readme conflicttunnckoCorebefore adoptione361ab5
line 29why, one step back29Merge branch 'master' into refactorJason Millerbefore adoption4799316
line 30why, one step back30This project uses [node](http://nodejs.org) and [npm](https://npmjs.com). Go check them out if you don't have them locally installed.31Merge branch 'master' into refactorJason Millerbefore adoption4799316
lines 32–34why, one step back32```sh33$ npm install --save mitt34```Spruce up the readme 🌲Jason Millerbefore adoption44362fe
line 35why, one step back35Merge branch 'master' into refactorJason Millerbefore adoption4799316
line 36why, one step back36Then 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 back37Merge branch 'master' into refactorJason Millerbefore adoption4799316
lines 38–50why, one step back38```javascript39// 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 back51Merge branch 'master' into refactorJason Millerbefore adoption4799316
lines 52–55why, one step back52You can find the library on `window.mitt`.5354## Usage55Spruce up the readme 🌲Jason Millerbefore adoption44362fe
lines 56–73why, one step back56```js57import 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) // unlistenInitial commit! 🚀Jason Millerbefore adoptione77a42c
lines 74–7574```75Typescript definitions (#25)Severinbefore adoptiond63b350
line 76why, one step back76### Typescript1.1.0Jason Millerbefore adoptionf147246
line 77why, one step back77Typescript definitions (#25)Severinbefore adoptiond63b350
lines 78–82why, one step back78```ts79import * as mitt from 'mitt';80let emitter: mitt.Emitter = new mitt();81```82Merge branch 'master' into refactorJason Millerbefore adoption4799316
line 83why, one step back83## Examples & Demos84Merge branch 'master' into refactorJason Millerbefore adoption4799316
lines 85–89why, one step back85<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 back9091* * *Merge branch 'master' into refactorJason Millerbefore adoption4799316
line 92why, one step back92Initial commit! 🚀Jason Millerbefore adoptione77a42c
lines 93–9493## API94Docs update.Jason Millerbefore adoptiona0578b7
lines 95–96why, one step back95<!-- Generated by documentation.js. Update this documentation by updating the source code. -->96Initial commit! 🚀Jason Millerbefore adoptione77a42c
lines 97–10097### mitt9899Mitt: Tiny (~200b) functional event emitter / pubsub.100refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 101–102why, one step back101**Parameters**102Docs update.Jason Millerbefore adoptiona0578b7
line 103why, one step back103- `all` **EventHandlerMap** refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 104why, one step back104Docs update.Jason Millerbefore adoptiona0578b7
lines 105–106why, one step back105Returns **Mitt** 106refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 107–108why, one step back107### on108Initial commit! 🚀Jason Millerbefore adoptione77a42c
lines 109–112109Register an event handler for the given type.110111**Parameters**112Docs update.Jason Millerbefore adoptiona0578b7
lines 113–114why, one step back113- `type` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Type of event to listen for, or `"*"` for all events114- `handler` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** Function to call in response to given event115refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 116–117why, one step back116### off117Initial commit! 🚀Jason Millerbefore adoptione77a42c
lines 118–121118Remove an event handler for the given type.119120**Parameters**121Docs update.Jason Millerbefore adoptiona0578b7
lines 122–133why, one step back122- `type` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Type of event to unregister `handler` from, or `"*"`123- `handler` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** Handler function to remove124125### emit126127Invoke all handlers for the given type.128If present, `"*"` handlers are invoked after type-matched handlers.129130**Parameters**131132- `type` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The event type to invoke133- `evt` **Any?** Any value (object is recommended and powerful), passed to each handlerMerge branch 'master' into refactorJason Millerbefore adoption4799316
lines 134–135why, one step back134135## ContributeUpdate docs.Jason Millerbefore adoption07f8819
line 136why, one step back136Merge branch 'master' into refactorJason Millerbefore adoption4799316
lines 137–139why, one step back137First off, thanks for taking the time to contribute!138Now, take a moment to be sure your contributions make sense to everyone else.139Add Standard Version for Semantic Releases (#43)Abhi Aiyerbefore adoptiond728e90
lines 140–145why, one step back140Development Start:141142This project is typed with Flow Type annotations. To ensure you have the proper typings for this project run143144`flow-typed install`145Merge branch 'master' into refactorJason Millerbefore adoption4799316
line 146why, one step back146### Reporting IssuesUpdate docs.Jason Millerbefore adoption07f8819
line 147why, one step back147Merge branch 'master' into refactorJason Millerbefore adoption4799316
lines 148–151why, one step back148Found a problem? Want a new feature? First of all see if your issue or idea has [already been reported](../../issues).149If don't, just open a [new clear and descriptive issue](../../issues/new).150151### Submitting pull requestsUpdate docs.Jason Millerbefore adoption07f8819
line 152why, one step back152Merge branch 'master' into refactorJason Millerbefore adoption4799316
lines 153–154why, one step back153Pull requests are the greatest contributions, so be sure they are focused in scope, and do avoid unrelated commits.154Update docs.Jason Millerbefore adoption07f8819
lines 155–163why, one step back155- Fork it!156- Clone your fork: `git clone https://github.com/<your-username>/mitt`157- Navigate to the newly cloned directory: `cd mitt`158- Create a new branch for the new feature: `git checkout -b my-new-feature`159- Install the tools necessary for development: `npm install`160- Make your changes.161- Commit your changes: `git commit -am 'Add some feature'`162- Push to the branch: `git push origin my-new-feature`163- Submit a pull request with full remarks documenting your changes.Merge branch 'master' into refactorJason Millerbefore adoption4799316
lines 164–166why, one step back164165## License166Update docs.Jason Millerbefore adoption07f8819
line 167why, one step back167[MIT License](LICENSE.md) © [Jason Miller](https://jasonformat.com/)