event-mux
Version:
69 lines (53 loc) • 2.12 kB
Markdown
[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![Test coverage][coveralls-image]][coveralls-url]
[![Downloads][downloads-image]][downloads-url]
[![js-standard-style][standard-image]][standard-url]
Duplex event multiplexer.
```bash
$ npm install event-mux
```
```js
const EventEmitter = require('events').EventEmitter
const mux = require('event-mux')
const emitter = mux({
1: new EventEmitter(),
2: new EventEmitter()
})
emitter.on('1:beep', () => console.log('beep called'))
emitter.on('2:boop', () => console.log('boop called'))
emitter.emit('1:beep')
// => 'beep called'
emitter.emit('2:boop')
// => 'boop called'
```
Compose multiple event emitters by namespacing them by their keys. Returns an
instance of [`EventEmitter2`][ee2].
Emit an event.
Listen to a namespaced event.
Using a lot of `EventEmitter`s in an application can lead to complex,
interdependent code. By wrapping emitters together the pain is mitigated by
being able to pass a single object around rather than pulling in each emitter
manually. This reduces complexity from `n^2` possible connections to `n`
connections.
[](https://tldrlegal.com/license/mit-license)
[]: https://img.shields.io/npm/v/event-mux.svg?style=flat-square
[]: https://npmjs.org/package/event-mux
[]: https://img.shields.io/travis/yoshuawuyts/event-mux.svg?style=flat-square
[]: https://travis-ci.org/yoshuawuyts/event-mux
[]: https://img.shields.io/coveralls/yoshuawuyts/event-mux.svg?style=flat-square
[]: https://coveralls.io/r/yoshuawuyts/event-mux?branch=master
[]: http://img.shields.io/npm/dm/event-mux.svg?style=flat-square
[]: https://npmjs.org/package/event-mux
[]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square
[]: https://github.com/feross/standard
[]: https://github.com/asyncly/EventEmitter2