From 44362fef76f92d3c6cc250a4238039e2178dce70 Mon Sep 17 00:00:00 2001 From: Jason Miller Date: Mon, 16 Jan 2017 10:42:44 -0500 Subject: Spruce up the readme 🌲 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 63 ++++++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 36 insertions(+), 27 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index 8978dae..6075466 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,46 @@ -# `mitt` +

+ mitt +
+ Mitt: tiny 200b functional event emitter / pubsub. +
+ npm travis +

-[![NPM](https://img.shields.io/npm/v/mitt.svg?style=flat)](https://www.npmjs.org/package/mitt) -[![travis-ci](https://travis-ci.org/developit/mitt.svg?branch=master)](https://travis-ci.org/developit/mitt) -**Tiny (~200b) functional event emitter / pubsub.** +## Why Mitt? + +- **Microscopic:** weighs less than 200 bytes gzipped +- **Useful:** a wildcard `"*"` event type listens to all events +- **Famliar:** same names & ideas as [Node's EventEmitter](https://nodejs.org/api/events.html#events_class_eventemitter) +- **Functional:** methods don't rely on `this` +- **Great Name:** somehow [mitt](https://npm.im/mitt) wasn't taken -**It's tiny:** no dependencies and only **190 bytes** when gzipped _(250b without)_. * * * -## Installation -```sh -npm install --save mitt +## Usage + +After installing via `npm install --save mitt`: + +```js +import mitt from 'mitt' + +let emitter = mitt() + +// listen to an event +emitter.on('foo', e => console.log('foo', e) ) + +// listen to all events +emitter.on('*', (type, e) => console.log(type, e) ) + +// fire an event +emitter.emit('foo', { a: 'b' }) + +// working with handler references: +function onFoo() {} +emitter.on('foo', onFoo) // listen +emitter.off('foo', onFoo) // unlisten ``` * * * @@ -52,22 +80,3 @@ If present, `"*"` handlers are invoked prior to type-matched handlers. - `type` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The event type to invoke - `event` **\[Any]** An event object, passed to each handler - -* * * - -## Sample usage - -```es6 -import mitt from 'mitt' - -let emitter = mitt() - -// listen to an event -emitter.on('foo', e => console.log('foo', e) ) - -// listen to all events -emitter.on('*', (type, e) => console.log(type, e) ) - -// fire an event -emitter.emit('foo', { a: 'b' }) -``` -- cgit v1.2.3