README.md
This file
Path
README.md
168 lines · 5.2 KiB · Markdown
Last changed by
Update sizesJason Millerbefore adoption2aba216
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>Update sizesJason Millerbefore adoption2aba216
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> <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 back5 Spruce up the readme 🌲Jason Millerbefore adoption44362fe
line 6why, one step back6</p>7Merge branch 'master' into refactorJason Millerbefore adoption4799316
line 8why, one step back8# Mitt9Merge branch 'master' into refactorJason Millerbefore adoption4799316
lines 10–11why, one step back10> Tiny 200b functional event emitter / pubsub.11readme, re-run build processtunnckoCorebefore adoption19a32dc
lines 12–16why, one step back12- **Microscopic:** weighs less than 200 bytes gzipped13- **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 taken17Merge branch 'master' into refactorJason Millerbefore adoption4799316
line 18why, one step back18Mitt 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 back19Merge branch 'master' into refactorJason Millerbefore adoption4799316
line 20why, one step back20## Table of Contentsresolve readme conflicttunnckoCorebefore adoptione361ab5
line 21why, one step back21Update docs.Jason Millerbefore adoption07f8819
lines 22–28why, one step back22- [Install](#install)23- [Usage](#usage)24- [Examples & Demos](#examples--demos)25- [API](#api)26- [Contribute](#contribute)27- [License](#license)28Merge branch 'master' into refactorJason Millerbefore adoption4799316
line 29why, one step back29## Installresolve readme conflicttunnckoCorebefore adoptione361ab5
line 30why, one step back30Merge branch 'master' into refactorJason Millerbefore adoption4799316
line 31why, one step back31This project uses [node](http://nodejs.org) and [npm](https://npmjs.com). Go check them out if you don't have them locally installed.32Merge branch 'master' into refactorJason Millerbefore adoption4799316
lines 33–35why, one step back33```sh34$ npm install --save mitt35```Spruce up the readme 🌲Jason Millerbefore adoption44362fe
line 36why, one step back36Merge branch 'master' into refactorJason Millerbefore adoption4799316
line 37why, one step back37Then 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 back38Merge branch 'master' into refactorJason Millerbefore adoption4799316
lines 39–51why, one step back39```javascript40// 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 back52Merge branch 'master' into refactorJason Millerbefore adoption4799316
lines 53–56why, one step back53You can find the library on `window.mitt`.5455## Usage56Spruce up the readme 🌲Jason Millerbefore adoption44362fe
lines 57–59why, one step back57```js58import mitt from 'mitt'59Fixing TypeScript usage. Fixes #60 (#67)David Khourshidbefore adoption0f4e8f0
line 60why, one step back60const emitter = mitt()Spruce up the readme 🌲Jason Millerbefore adoption44362fe
lines 61–74why, one step back6162// 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) // unlistenInitial commit! 🚀Jason Millerbefore adoptione77a42c
lines 75–7675```76Typescript definitions (#25)Severinbefore adoptiond63b350
line 77why, one step back77### Typescript1.1.0Jason Millerbefore adoptionf147246
line 78why, one step back78Typescript definitions (#25)Severinbefore adoptiond63b350
line 79why, one step back79```tsFixing TypeScript usage. Fixes #60 (#67)David Khourshidbefore adoption0f4e8f0
lines 80–81why, one step back80import mitt from 'mitt';81const emitter: mitt.Emitter = mitt();Typescript definitions (#25)Severinbefore adoptiond63b350
lines 82–83why, one step back82```83Merge branch 'master' into refactorJason Millerbefore adoption4799316
line 84why, one step back84## Examples & Demos85Merge branch 'master' into refactorJason Millerbefore adoption4799316
lines 86–90why, one step back86<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 back9192* * *Merge branch 'master' into refactorJason Millerbefore adoption4799316
line 93why, one step back93Initial commit! 🚀Jason Millerbefore adoptione77a42c
lines 94–9594## API95Docs update.Jason Millerbefore adoptiona0578b7
lines 96–97why, one step back96<!-- Generated by documentation.js. Update this documentation by updating the source code. -->97Initial commit! 🚀Jason Millerbefore adoptione77a42c
lines 98–10198### mitt99100Mitt: Tiny (~200b) functional event emitter / pubsub.101refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 102–103why, one step back102**Parameters**103Docs update.Jason Millerbefore adoptiona0578b7
line 104why, one step back104- `all` **EventHandlerMap** refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
line 105why, one step back105Docs update.Jason Millerbefore adoptiona0578b7
lines 106–107why, one step back106Returns **Mitt** 107refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 108–109why, one step back108### on109Initial commit! 🚀Jason Millerbefore adoptione77a42c
lines 110–113110Register an event handler for the given type.111112**Parameters**113Docs update.Jason Millerbefore adoptiona0578b7
lines 114–115why, one step back114- `type` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Type of event to listen for, or `"*"` for all events115- `handler` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** Function to call in response to given event116refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 117–118why, one step back117### off118Initial commit! 🚀Jason Millerbefore adoptione77a42c
lines 119–122119Remove an event handler for the given type.120121**Parameters**122Docs update.Jason Millerbefore adoptiona0578b7
lines 123–134why, one step back123- `type` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Type of event to unregister `handler` from, or `"*"`124- `handler` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** Handler function to remove125126### emit127128Invoke all handlers for the given type.129If present, `"*"` handlers are invoked after type-matched handlers.130131**Parameters**132133- `type` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The event type to invoke134- `evt` **Any?** Any value (object is recommended and powerful), passed to each handlerMerge branch 'master' into refactorJason Millerbefore adoption4799316
lines 135–136why, one step back135136## ContributeUpdate docs.Jason Millerbefore adoption07f8819
line 137why, one step back137Merge branch 'master' into refactorJason Millerbefore adoption4799316
lines 138–140why, one step back138First off, thanks for taking the time to contribute!139Now, take a moment to be sure your contributions make sense to everyone else.140Add Standard Version for Semantic Releases (#43)Abhi Aiyerbefore adoptiond728e90
lines 141–146why, one step back141Development Start:142143This project is typed with Flow Type annotations. To ensure you have the proper typings for this project run144145`flow-typed install`146Merge branch 'master' into refactorJason Millerbefore adoption4799316
line 147why, one step back147### Reporting IssuesUpdate docs.Jason Millerbefore adoption07f8819
line 148why, one step back148Merge branch 'master' into refactorJason Millerbefore adoption4799316
lines 149–152why, one step back149Found a problem? Want a new feature? First of all see if your issue or idea has [already been reported](../../issues).150If don't, just open a [new clear and descriptive issue](../../issues/new).151152### Submitting pull requestsUpdate docs.Jason Millerbefore adoption07f8819
line 153why, one step back153Merge branch 'master' into refactorJason Millerbefore adoption4799316
lines 154–155why, one step back154Pull requests are the greatest contributions, so be sure they are focused in scope, and do avoid unrelated commits.155Update docs.Jason Millerbefore adoption07f8819
lines 156–164why, one step back156- Fork it!157- Clone your fork: `git clone https://github.com/<your-username>/mitt`158- Navigate to the newly cloned directory: `cd mitt`159- Create a new branch for the new feature: `git checkout -b my-new-feature`160- Install the tools necessary for development: `npm install`161- Make your changes.162- Commit your changes: `git commit -am 'Add some feature'`163- Push to the branch: `git push origin my-new-feature`164- Submit a pull request with full remarks documenting your changes.Merge branch 'master' into refactorJason Millerbefore adoption4799316
lines 165–167why, one step back165166## License167Clean up repo rootJason Millerbefore adoption4a8e0a5
line 168why, one step back168[MIT License](https://opensource.org/licenses/MIT) © [Jason Miller](https://jasonformat.com/)