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

emitter-component

Package Overview
Dependencies
Maintainers
22
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

emitter-component

Event emitter

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
411K
decreased by-41.19%
Maintainers
22
Weekly downloads
 
Created

What is emitter-component?

The emitter-component npm package is a simple event emitter implementation. It allows you to create objects that can emit events and have listeners that respond to those events. This is useful for decoupling different parts of an application and enabling communication between them.

What are emitter-component's main functionalities?

Event Emission

This feature allows you to emit events and have listeners respond to those events. In the code sample, an event listener is defined for the 'event' event, and then the event is emitted with a message.

const Emitter = require('emitter-component');
const emitter = new Emitter();

// Define an event listener
emitter.on('event', function(message) {
  console.log('Event received:', message);
});

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

Removing Event Listeners

This feature allows you to remove event listeners. In the code sample, an event listener is defined and then removed before the event is emitted, so no listeners respond to the event.

const Emitter = require('emitter-component');
const emitter = new Emitter();

function onEvent(message) {
  console.log('Event received:', message);
}

// Define an event listener
emitter.on('event', onEvent);

// Remove the event listener
emitter.off('event', onEvent);

// Emit an event (no listeners should respond)
emitter.emit('event', 'Hello, World!');

Once Event Listeners

This feature allows you to define event listeners that will be called only once. In the code sample, the event listener is defined with the 'once' method and is called only the first time the event is emitted.

const Emitter = require('emitter-component');
const emitter = new Emitter();

// Define an event listener that will be called only once
emitter.once('event', function(message) {
  console.log('Event received:', message);
});

// Emit the event twice
emitter.emit('event', 'Hello, World!');
emitter.emit('event', 'Hello again!');

Other packages similar to emitter-component

FAQs

Package last updated on 16 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

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