Socket
Socket
Sign inDemoInstall

wolfy87-eventemitter

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wolfy87-eventemitter

Event based JavaScript for the browser


Version published
Weekly downloads
164K
increased by10%
Maintainers
1
Weekly downloads
 
Created

What is wolfy87-eventemitter?

The wolfy87-eventemitter package is a lightweight and flexible event emitter library for JavaScript. It allows you to create and manage custom events, making it easier to implement the observer pattern in your applications.

What are wolfy87-eventemitter's main functionalities?

Basic Event Emission

This feature allows you to create an event emitter instance, register an event listener, and emit an event. The listener will be triggered when the event is emitted.

const EventEmitter = require('wolfy87-eventemitter');
const emitter = new EventEmitter();

emitter.on('event', function() {
  console.log('Event triggered!');
});

emitter.emit('event');

Event Emission with Arguments

This feature allows you to emit events with arguments. The registered listener can then access these arguments when the event is triggered.

const EventEmitter = require('wolfy87-eventemitter');
const emitter = new EventEmitter();

emitter.on('event', function(arg1, arg2) {
  console.log('Event triggered with arguments:', arg1, arg2);
});

emitter.emit('event', 'arg1', 'arg2');

Removing Event Listeners

This feature allows you to remove specific event listeners. In this example, the listener is removed before the event is emitted, so the console log will not be triggered.

const EventEmitter = require('wolfy87-eventemitter');
const emitter = new EventEmitter();

function listener() {
  console.log('Event triggered!');
}

emitter.on('event', listener);
emitter.off('event', listener);
emitter.emit('event');

Once Event Listeners

This feature allows you to register a listener that will only be triggered once. After the event is emitted the first time, the listener is automatically removed.

const EventEmitter = require('wolfy87-eventemitter');
const emitter = new EventEmitter();

emitter.once('event', function() {
  console.log('Event triggered only once!');
});

emitter.emit('event');
emitter.emit('event');

Other packages similar to wolfy87-eventemitter

Keywords

FAQs

Package last updated on 16 Jun 2016

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