emit-mapper
Re-emit events while mapping them to new names.
Last updated 2 years ago by phated .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install emit-mapper 
SYNC missed versions from official npm registry.

emit-mapper

NPM version Downloads Azure Pipelines Build Status Travis Build Status AppVeyor Build Status Coveralls Status Gitter chat

Re-emit events while mapping them to new names.

Usage

var src = new EventEmitter();
var dest = new EventEmitter();
var events = {
  before: 'preload:before',
  success: 'preload:success',
  failure: 'preload:failure',
};

var cleanup = emitMapper(src, dest, events);

dest.on('preload:before', console.log);
dest.on('preload:success', console.log);
dest.on('preload:failure', console.log);

src.emit('before', 'some value');
src.emit('success', 1, 2, 3);
src.emit('failure', 'moduleName', new Error('some error'));

// No more events will be re-emitted after cleanup
cleanup();

src.emit('before', 'not re-emitted');

API

emitMapper(source, destination, eventMapping)

Takes a source EventEmitter, a destination EventEmitter, and an eventMapping object that maps source events to destination events. Whenever an event from the eventMapping object is emitted on source, a new event will be emitted on destination with the mapped named but containing all the same arguments.

Returns a cleanup method to remove all handlers registered for re-emitting.

Prior art

This module is heavily inspired by re-emitter but the ability to map event names to new names was needed. Also, this module supports back to node 0.10 while re-emitter only supports node LTS versions.

License

MIT

Current Tags

  • 1.0.0                                ...           latest (2 years ago)

1 Versions

  • 1.0.0                                ...           2 years ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (6)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |