Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

forward-emitter

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

forward-emitter - npm Package Compare versions

Comparing version 0.0.1 to 0.1.0

14

index.js

@@ -10,11 +10,15 @@ 'use strict';

// Listeners bound to the destination emitter should be bound to the source emitter.
dest.on('newListener', function(eventName, listener) {
if (filterFn(eventName)) src.on(eventName, listener);
});
dest.on('newListener', newListener);
function newListener(eventName, listener) {
if (filterFn(eventName) && listener !== removeListener) src.on(eventName, listener);
}
// 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', function(eventName, listener) {
dest.on('removeListener', removeListener);
function removeListener(eventName, listener) {
src.removeListener(eventName, listener);
});
}
};
{
"name": "forward-emitter",
"version": "0.0.1",
"version": "0.1.0",
"description": "Forward events from any Node EventEmitter to another EventEmitter.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -30,2 +30,22 @@ 'use strict';

it('should forward in a chain', function() {
var a = new EventEmitter();
var b = new EventEmitter();
var c = new EventEmitter();
forward(a, b);
forward(b, c);
var calls = 0;
a.on('test', increment);
b.on('test', increment);
c.on('test', increment);
function increment() {
calls++;
}
a.emit('test', 'event payload');
calls.should.equal(3);
});
it('should forward errors', function(done){

@@ -43,2 +63,14 @@ var src = new EventEmitter();

});
it('should not loop forever', function(done) {
var src1 = new EventEmitter();
var src2 = new EventEmitter();
var src3 = new EventEmitter();
var dest = new EventEmitter();
forward(src1, dest);
forward(src2, dest);
forward(src3, dest);
done();
});
});

@@ -45,0 +77,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc