Socket
Socket
Sign inDemoInstall

intercept-events

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    intercept-events

Intercept (add listeners to) all events from events.EventEmitter.


Version published
Maintainers
1
Install size
5.01 kB
Created

Readme

Source

intercept-events

Intercept all events from events.EventEmitter.

With this module you can add and remove listeners, that will fire on all events (emits).

The only difference between a normal listeners and these listeners is, that the event type will be the first argument:

var util = require('util');
var EventEmitter = require('events').EventEmitter;
var interceptEvents = require('./index');

var MyClass = function() {
  EventEmitter.call(this);
};
util.inherits(MyClass, EventEmitter);

MyClass.prototype.test = function() {
  this.emit('my test', { the: 'data' });
};
var myClass = new MyClass();

myClass.on('my test', function() {
  console.log('From normal listener:');
  console.log(arguments);
});

var myListener1 = function() {
  console.log('From intercept listener 1:');
  console.log(arguments);
};

var myListener2 = function() {
  console.log('From intercept listener 2:');
  console.log(arguments);
};

interceptEvents.addListener(myListener1);
interceptEvents.addListener(myListener2);

myClass.test();

interceptEvents.removeListener(myListener2);

myClass.test();

This will output this:

From intercept listener 1:
{ '0': 'my test', '1': { the: 'data' } }
From intercept listener 2:
{ '0': 'my test', '1': { the: 'data' } }
From normal listener:
{ '0': { the: 'data' } }
From intercept listener 1:
{ '0': 'my test', '1': { the: 'data' } }
From normal listener:
{ '0': { the: 'data' } }
From intercept listener 1:
{ '0': 'exit', '1': 0 }

This is an early BETA version

As soon as the module has shown it's worth and stability on a live system, it will be marked as version >= 1.0.0.

Until then: Feel free to play around with it, learn from it.

To install

npm install intercept-events

Keywords

FAQs

Last updated on 06 Aug 2013

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc