Duplex event multiplexer.
$ npm install event-mux
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.
Emit an event.
Listen to a namespaced event.
Using a lot of EventEmitters 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.