Socket
Socket
Sign inDemoInstall

event-pubsub

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

event-pubsub

Super light and fast Extensible PubSub events and EventEmitters for Node and the browser with support for ES6 by default, and ES5 versions for older verions of node and older IE/Safari versions. Easy for any developer level. No frills, just high speed pub


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

What is event-pubsub?

The event-pubsub package is a Node.js module that provides a simple interface for implementing the publish-subscribe pattern. This pattern allows for the creation of a decoupled system where publishers and subscribers can communicate through events without being directly connected.

What are event-pubsub's main functionalities?

Event Emission

This feature allows you to emit events with a specified name and pass data to the event listeners. In the code sample, an event listener is set up to listen for the 'sayHello' event and emit that event with a parameter.

const EventPubSub = require('event-pubsub');
const events = new EventPubSub();

// Event listener
events.on('sayHello', name => console.log(`Hello, ${name}!`));

// Emit event
events.emit('sayHello', 'World');

Event Listening

This feature allows you to listen for events by name. When the event is emitted, the callback function is called with any data passed to the event. In the code sample, an event listener is set up to listen for the 'dataReceived' event.

const EventPubSub = require('event-pubsub');
const events = new EventPubSub();

// Event listener
events.on('dataReceived', data => console.log(`Data: ${data}`));

Once Listeners

This feature allows you to set up event listeners that will only be triggered once. After the event is emitted and the listener is invoked, the listener is removed. In the code sample, an event listener is set up to listen for the 'initialize' event and will only be triggered once.

const EventPubSub = require('event-pubsub');
const events = new EventPubSub();

// Event listener that fires once
events.once('initialize', () => console.log('Initialization complete.'));

Removing Listeners

This feature allows you to remove specific event listeners. In the code sample, an event listener is added and then removed for the 'message' event.

const EventPubSub = require('event-pubsub');
const events = new EventPubSub();

function onMessage(content) {
  console.log(`Message: ${content}`);
}

// Add and remove an event listener
events.on('message', onMessage);
events.off('message', onMessage);

Other packages similar to event-pubsub

Keywords

FAQs

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