README.md
This file
Path
README.md
156 lines · 5.2 KiB · Markdown
Last changed by
Typescript definitions (#25)Severinbefore adoptiond63b350
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
lines 19–25why, one step back19## Table of Contents20- [Install](#install)21- [Usage](#usage)22- [Examples & Demos](#examples--demos)23- [API](#api)24- [Contribute](#contribute)25- [License](#license)resolve readme conflicttunnckoCorebefore adoptione361ab5
line 26why, one step back26Merge branch 'master' into refactorJason Millerbefore adoption4799316
line 27why, one step back27## Installresolve readme conflicttunnckoCorebefore adoptione361ab5
line 28why, one step back28Merge branch 'master' into refactorJason Millerbefore adoption4799316
line 29why, one step back29This project uses [node](http://nodejs.org) and [npm](https://npmjs.com). Go check them out if you don't have them locally installed.30Merge branch 'master' into refactorJason Millerbefore adoption4799316
lines 31–33why, one step back31```sh32$ npm install --save mitt33```Spruce up the readme 🌲Jason Millerbefore adoption44362fe
line 34why, one step back34Merge branch 'master' into refactorJason Millerbefore adoption4799316
line 35why, one step back35Then 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 36why, one step back36Merge branch 'master' into refactorJason Millerbefore adoption4799316
lines 37–53why, one step back37```javascript38// using ES6 modules39import mitt from 'mitt'4041// using CommonJS modules42var mitt = require('mitt')43```4445The [UMD](https://github.com/umdjs/umd) build is also available on [unpkg](https://unpkg.com):4647```html48<script src="https://unpkg.com/mitt/dist/mitt.umd.js"></script>49```50You can find the library on `window.mitt`.5152## Usage53Spruce up the readme 🌲Jason Millerbefore adoption44362fe
lines 54–71why, one step back54```js55import mitt from 'mitt'5657let emitter = mitt()5859// listen to an event60emitter.on('foo', e => console.log('foo', e) )6162// listen to all events63emitter.on('*', (type, e) => console.log(type, e) )6465// fire an event66emitter.emit('foo', { a: 'b' })6768// working with handler references:69function onFoo() {}70emitter.on('foo', onFoo) // listen71emitter.off('foo', onFoo) // unlistenInitial commit! 🚀Jason Millerbefore adoptione77a42c
lines 72–7372```73Typescript definitions (#25)Severinbefore adoptiond63b350
lines 74–79why, one step back74### Typescript75```ts76import * as mitt from 'mitt';77let emitter: mitt.Emitter = new mitt();78```79Merge branch 'master' into refactorJason Millerbefore adoption4799316
line 80why, one step back80## Examples & Demos81Merge branch 'master' into refactorJason Millerbefore adoption4799316
lines 82–86why, one step back82<a href="http://codepen.io/developit/pen/rjMEwW?editors=0110">83 <b>Preact + Mitt Codepen Demo</b>84 <br>85 <img src="https://i.imgur.com/CjBgOfJ.png" width="278" alt="preact + mitt preview">86</a>Typescript definitions (#25)Severinbefore adoptiond63b350
lines 87–88why, one step back8788* * *Merge branch 'master' into refactorJason Millerbefore adoption4799316
line 89why, one step back89Initial commit! 🚀Jason Millerbefore adoptione77a42c
lines 90–9590## API9192### mitt9394Mitt: Tiny (~200b) functional event emitter / pubsub.95Merge branch 'master' into refactorJason Millerbefore adoption4799316
line 96why, one step back96Returns **Mitt**97refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 98why, one step back98#### emit99refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 100–105why, one step back100Invoke all handlers for the given type.101If present, `"*"` handlers are invoked prior to type-matched handlers.102103**Parameters**104105- `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 106why, one step back106- `evt` **\[Any]** Any value (object is recommended and powerful), passed to each handlerrefactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 107–111why, one step back107108Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** the `mitt` instance for chaining109110### on111Initial commit! 🚀Jason Millerbefore adoptione77a42c
lines 112–116112Register an event handler for the given type.113114**Parameters**115116- `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 117why, one step back117- `handler` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** Function to call in response to given event118refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 119why, one step back119Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** the `mitt` instance for chaining120refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 121–122why, one step back121### off122Initial commit! 🚀Jason Millerbefore adoptione77a42c
lines 123–129123Remove an event handler for the given type.124125**Parameters**126127- `type` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Type of event to unregister `handler` from, or `"*"`128- `handler` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** Handler function to remove129refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 130why, one step back130Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** the `mitt` instance for chainingMerge branch 'master' into refactorJason Millerbefore adoption4799316
lines 131–156why, one step back131132## Contribute133First off, thanks for taking the time to contribute!134Now, take a moment to be sure your contributions make sense to everyone else.135136### Reporting Issues137Found a problem? Want a new feature? First of all see if your issue or idea has [already been reported](../../issues).138If don't, just open a [new clear and descriptive issue](../../issues/new).139140### Submitting pull requests141Pull requests are the greatest contributions, so be sure they are focused in scope, and do avoid unrelated commits.142143- Fork it!144- Clone your fork: `git clone https://github.com/<your-username>/mitt`145- Navigate to the newly cloned directory: `cd mitt`146- Create a new branch for the new feature: `git checkout -b my-new-feature`147- Install the tools necessary for development: `npm install`148- Make your changes.149- Commit your changes: `git commit -am 'Add some feature'`150- Push to the branch: `git push origin my-new-feature`151- Submit a pull request with full remarks documenting your changes.152153## License154155[MIT License](LICENSE.md) © [Jason Miller](https://jasonformat.com/)156