emit-mapper
Re-emit events while mapping them to new names.
Usage
var src = ;var dest = ;var events = before: 'preload:before' success: 'preload:success' failure: 'preload:failure'; var cleanup = ; dest;dest;dest; src;src;src; // No more events will be re-emitted after cleanup; src;
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