eavesdrop

Listen in on EventEmitters

Usage no npm install needed!

<script type="module">
  import eavesdrop from 'https://cdn.skypack.dev/eavesdrop';
</script>

README

eavesdrop Build Status

Listen on other EventEmitters

Usage

Listen on all events:

eavesdrop(source, target)
target.on('data', function (arg) {
  // => foo
})
source.emit('data', 'foo')

Listen on specific events:

eavesdrop(source, target, ['data', 'end'])
target.on('finish', function (arg) {
  // => never called
})
source.emit('finish', 'foo')

API

eavesdrop(source, target, [events]) -> off

Listens on source events and re-emits them on the target. If specific events are provided, an array of the registered event listeners is returned. Otherwise, a function is returned that will stop proxying events when called.

source

Required
Type: eventEmitter

The source emitter that will emit the original events.

target

Required
Type: eventEmitter

The target emitter where events will be proxied.

events

Type: array[string]

An array of events (or variadic arguments) to listen on.

License

MIT © Ben Drucker