Socket
Socket
Sign inDemoInstall

@socket.io/component-emitter

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@socket.io/component-emitter

Event emitter


Version published
Weekly downloads
5.2M
decreased by-4.37%
Maintainers
1
Weekly downloads
 
Created

What is @socket.io/component-emitter?

@socket.io/component-emitter is a lightweight event emitter library that allows you to create and manage custom events. It is commonly used in applications where you need to implement an event-driven architecture, such as in real-time web applications.

What are @socket.io/component-emitter's main functionalities?

Event Emission

This feature allows you to emit custom events and listen for them. In the code sample, an event named 'event' is emitted, and a listener logs a message to the console when the event occurs.

const Emitter = require('@socket.io/component-emitter');
const emitter = new Emitter();
emitter.on('event', function() {
  console.log('An event occurred!');
});
emitter.emit('event');

Event Removal

This feature allows you to remove specific event listeners. In the code sample, the listener for the 'event' is removed before the event is emitted, so no message is logged to the console.

const Emitter = require('@socket.io/component-emitter');
const emitter = new Emitter();
function response() {
  console.log('An event occurred!');
}
emitter.on('event', response);
emitter.off('event', response);
emitter.emit('event');

Once Event Listener

This feature allows you to add a listener that will be called at most once for a particular event. In the code sample, the listener logs a message only the first time the 'event' is emitted.

const Emitter = require('@socket.io/component-emitter');
const emitter = new Emitter();
emitter.once('event', function() {
  console.log('This will only log once');
});
emitter.emit('event');
emitter.emit('event');

Other packages similar to @socket.io/component-emitter

FAQs

Package last updated on 26 Apr 2024

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

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