README.md
This file
Path
README.md
170 lines · 5.3 KiB · Markdown
Last changed by
Add note about manually firing "*" handlersJason Millerbefore adoptioncfd246c
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–130why, 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.130Add note about manually firing "*" handlersJason Millerbefore adoptioncfd246c
lines 131–132why, one step back131_Note: Manually firing "*" handlers is not supported._132Docs update.Jason Millerbefore adoptiona0578b7
lines 133–136why, one step back133**Parameters**134135- `type` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The event type to invoke136- `evt` **Any?** Any value (object is recommended and powerful), passed to each handlerMerge branch 'master' into refactorJason Millerbefore adoption4799316
lines 137–138why, one step back137138## ContributeUpdate docs.Jason Millerbefore adoption07f8819
line 139why, one step back139Merge branch 'master' into refactorJason Millerbefore adoption4799316
lines 140–142why, one step back140First off, thanks for taking the time to contribute!141Now, take a moment to be sure your contributions make sense to everyone else.142Add Standard Version for Semantic Releases (#43)Abhi Aiyerbefore adoptiond728e90
lines 143–148why, one step back143Development Start:144145This project is typed with Flow Type annotations. To ensure you have the proper typings for this project run146147`flow-typed install`148Merge branch 'master' into refactorJason Millerbefore adoption4799316
line 149why, one step back149### Reporting IssuesUpdate docs.Jason Millerbefore adoption07f8819
line 150why, one step back150Merge branch 'master' into refactorJason Millerbefore adoption4799316
lines 151–154why, one step back151Found a problem? Want a new feature? First of all see if your issue or idea has [already been reported](../../issues).152If don't, just open a [new clear and descriptive issue](../../issues/new).153154### Submitting pull requestsUpdate docs.Jason Millerbefore adoption07f8819
line 155why, one step back155Merge branch 'master' into refactorJason Millerbefore adoption4799316
lines 156–157why, one step back156Pull requests are the greatest contributions, so be sure they are focused in scope, and do avoid unrelated commits.157Update docs.Jason Millerbefore adoption07f8819
lines 158–166why, one step back158- Fork it!159- Clone your fork: `git clone https://github.com/<your-username>/mitt`160- Navigate to the newly cloned directory: `cd mitt`161- Create a new branch for the new feature: `git checkout -b my-new-feature`162- Install the tools necessary for development: `npm install`163- Make your changes.164- Commit your changes: `git commit -am 'Add some feature'`165- Push to the branch: `git push origin my-new-feature`166- Submit a pull request with full remarks documenting your changes.Merge branch 'master' into refactorJason Millerbefore adoption4799316
lines 167–169why, one step back167168## License169Clean up repo rootJason Millerbefore adoption4a8e0a5
line 170why, one step back170[MIT License](https://opensource.org/licenses/MIT) © [Jason Miller](https://jasonformat.com/)