forward-emitter
Advanced tools
Comparing version
17
index.js
@@ -9,16 +9,17 @@ 'use strict'; | ||
// Listeners bound to the destination emitter should be bound to the source emitter. | ||
dest.on('newListener', newListener); | ||
function __forward_emitter_newListener(eventName, listener) { | ||
if (filterFn(eventName) && listener.name.indexOf('__forward_emitter_') !== 0) src.on(eventName, listener); | ||
} | ||
function newListener(eventName, listener) { | ||
if (filterFn(eventName) && listener !== removeListener) src.on(eventName, listener); | ||
function __forward_emitter_removeListener(eventName, listener) { | ||
src.removeListener(eventName, listener); | ||
} | ||
// Listeners bound to the destination emitter should be bound to the source emitter. | ||
dest.on('newListener', __forward_emitter_newListener); | ||
// When a listener is removed from the destination emitter, remove it from the source emitter | ||
// (otherwise it will continue to be called). | ||
dest.on('removeListener', removeListener); | ||
dest.on('removeListener', __forward_emitter_removeListener); | ||
function removeListener(eventName, listener) { | ||
src.removeListener(eventName, listener); | ||
} | ||
}; |
{ | ||
"name": "forward-emitter", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Forward events from any Node EventEmitter to another EventEmitter.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -67,2 +67,3 @@ 'use strict'; | ||
var src3 = new EventEmitter(); | ||
var src4 = new EventEmitter(); | ||
var dest = new EventEmitter(); | ||
@@ -72,2 +73,3 @@ forward(src1, dest); | ||
forward(src3, dest); | ||
forward(src4, dest); | ||
@@ -74,0 +76,0 @@ done(); |
5433
2.94%121
1.68%