Skip to content
Myr

Merge branch 'master' into refactor

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Jason Miller · committed by GitHub · parents 70e8ad1, 1fbe781 · Browse files · 4 files+95 added−24 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+95 added−24 removed

  • other:+95 added−24 removed

4 files+95 added−24 removed

added:.babelrc+3 added
1{2 "presets": ["es2015", "stage-0"]3}
added:LICENSE.md+21 added
modified:package.json+1 added-7 removed
modified:README.md+70 added-17 removed
1<p align="center">2 <img src="https://i.imgur.com/BqsX9NT.png" width="256" height="256" alt="mitt">2 <img src="https://i.imgur.com/BqsX9NT.png" width="300" height="300" alt="mitt">3 <br>4 <b>Mitt</b>: tiny 200b functional event emitter / pubsub.5 <br>6 <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>4 <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>5</p>69## Why Mitt?7# Mitt89> Tiny 200b functional event emitter / pubsub.1011- **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 taken1617> Mitt was made for the browser, but works in any JavaScript runtime. It has no dependencies and supports IE9+.17Mitt was made for the browser, but works in any JavaScript runtime. It has no dependencies and supports IE9+.1819## Examples & Demos19## Table of Contents20- [Install](#install)21- [Usage](#usage)22- [Examples & Demos](#examples--demos)23- [API](#api)24- [Contribute](#contribute)25- [License](#license)2621<a href="http://codepen.io/developit/pen/rjMEwW?editors=0110">22 <b>Preact + Mitt Codepen Demo</b>23 <br>24 <img src="https://i.imgur.com/CjBgOfJ.png" width="278" alt="preact + mitt preview">25</a>27## Install2827* * *29This project uses [node](http://nodejs.org) and [npm](https://npmjs.com). Go check them out if you don't have them locally installed.3029## Usage31```sh32$ npm install --save mitt33```3431After installing via `npm install --save mitt`:35Then with a module bundler like [rollup](http://rollupjs.org/) or [webpack](https://webpack.js.org/), use as you would anything else:3637```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## Usage5354```js55import mitt from 'mitt'5657let emitter = mitt()
12 unmodified lines
70emitter.on('foo', onFoo) // listen71emitter.off('foo', onFoo) // unlisten72```7353* * *74## Examples & Demos7576<a href="http://codepen.io/developit/pen/rjMEwW?editors=0110">77 <b>Preact + Mitt Codepen Demo</b>78 <br>79 <img src="https://i.imgur.com/CjBgOfJ.png" width="278" alt="preact + mitt preview">80</a>8182## API8384### mitt8586Mitt: Tiny (~200b) functional event emitter / pubsub.8761Returns **Mitt** 88Returns **Mitt**8990#### emit9192Invoke all handlers for the given type.
26 unmodified lines
119- `type` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Type of event to unregister `handler` from, or `"*"`120- `handler` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** Handler function to remove121122Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** the `mitt` instance for chaining123124## Contribute125First off, thanks for taking the time to contribute!126Now, take a moment to be sure your contributions make sense to everyone else.127128### Reporting Issues129Found a problem? Want a new feature? First of all see if your issue or idea has [already been reported](../../issues).130If don't, just open a [new clear and descriptive issue](../../issues/new).131132### Submitting pull requests133Pull requests are the greatest contributions, so be sure they are focused in scope, and do avoid unrelated commits.134135- Fork it!136- Clone your fork: `git clone https://github.com/<your-username>/mitt`137- Navigate to the newly cloned directory: `cd mitt`138- Create a new branch for the new feature: `git checkout -b my-new-feature`139- Install the tools necessary for development: `npm install`140- Make your changes.141- Commit your changes: `git commit -am 'Add some feature'`142- Push to the branch: `git push origin my-new-feature`143- Submit a pull request with full remarks documenting your changes.144145## License146147[MIT License](LICENSE.md) &copy; [Jason Miller](https://jasonformat.com/)148