README.md
This file
Path
README.md
170 lines · 5.6 KiB · Markdown
Last changed by
Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
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. -->97Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
lines 98–107why, one step back98#### Table of Contents99100- [mitt](#mitt)101- [on](#on)102 - [Parameters](#parameters)103- [off](#off)104 - [Parameters](#parameters-1)105- [emit](#emit)106 - [Parameters](#parameters-2)107Initial commit! 🚀Jason Millerbefore adoptione77a42c
lines 108–111108### mitt109110Mitt: Tiny (~200b) functional event emitter / pubsub.111Docs update.Jason Millerbefore adoptiona0578b7
lines 112–113why, one step back112Returns **Mitt** 113refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 114–115why, one step back114### on115Initial commit! 🚀Jason Millerbefore adoptione77a42c
lines 116–117116Register an event handler for the given type.117Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
line 118why, one step back118#### Parameters119Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
line 120why, one step back120- `type` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [symbol](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Symbol))** Type of event to listen for, or `"*"` for all eventsDocs update.Jason Millerbefore adoptiona0578b7
line 121why, one step back121- `handler` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** Function to call in response to given event122refactor: fixes #2, #6, #12 and #13tunnckoCorebefore adoptiona6190e9
lines 123–124why, one step back123### off124Initial commit! 🚀Jason Millerbefore adoptione77a42c
lines 125–126125Remove an event handler for the given type.126Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
line 127why, one step back127#### Parameters128Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
line 129why, one step back129- `type` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [symbol](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Symbol))** Type of event to unregister `handler` from, or `"*"`Docs update.Jason Millerbefore adoptiona0578b7
lines 130–136why, one step back130- `handler` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** Handler function to remove131132### emit133134Invoke all handlers for the given type.135If present, `"*"` handlers are invoked after type-matched handlers.136Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
line 137why, one step back137Note: Manually firing "\*" handlers is not supported.Add note about manually firing "*" handlersJason Millerbefore adoptioncfd246c
line 138why, one step back138Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
line 139why, one step back139#### ParametersDocs update.Jason Millerbefore adoptiona0578b7
line 140why, one step back140Migrate to TypeScript and use Map (#99)Jack Franklinbefore adoptionbe5237f
line 141why, one step back141- `type` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [symbol](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Symbol))** The event type to invokeDocs update.Jason Millerbefore adoptiona0578b7
line 142why, one step back142- `evt` **Any?** Any value (object is recommended and powerful), passed to each handlerMerge branch 'master' into refactorJason Millerbefore adoption4799316
lines 143–144why, one step back143144## ContributeUpdate docs.Jason Millerbefore adoption07f8819
line 145why, one step back145Merge branch 'master' into refactorJason Millerbefore adoption4799316
lines 146–147why, one step back146First off, thanks for taking the time to contribute!147Now, take a moment to be sure your contributions make sense to everyone else.Add Standard Version for Semantic Releases (#43)Abhi Aiyerbefore adoptiond728e90
line 148why, one step back148Merge 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/)