🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

component-emitter

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

component-emitter

Simple event emitter

2.0.0
latest
Version published
Weekly downloads
18M
-8.02%
Maintainers
33
Weekly downloads
 
Created

What is component-emitter?

The component-emitter package is a simple event emitter implementation that allows objects to subscribe to events, emit events, and remove event listeners. It is often used to add observer pattern capabilities to objects, enabling event-driven programming.

What are component-emitter's main functionalities?

Event subscription

This feature allows an object to listen for specific events using the 'on' method. When the event is emitted, the callback function is called.

const Emitter = require('component-emitter');
let emitter = new Emitter();
emitter.on('event', function(message) {
  console.log(message);
});

Event emission

This feature allows an object to emit an event, optionally passing arguments to the event listeners.

emitter.emit('event', 'Hello World!');

One-time event subscription

This feature allows an object to listen for an event only once. After the event is emitted and the listener is invoked, the listener is removed.

emitter.once('event', function(message) {
  console.log(message);
});

Event unsubscription

This feature allows an object to stop listening for specific events using the 'off' method.

function listener(message) {
  console.log(message);
}
emitter.on('event', listener);
emitter.off('event', listener);

Other packages similar to component-emitter

FAQs

Package last updated on 17 Nov 2023

Did you know?

Socket

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