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

pubsub-js

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pubsub-js

Dependency free publish/subscribe library

  • 1.4.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
206K
increased by2.8%
Maintainers
1
Weekly downloads
 
Created

What is pubsub-js?

PubSub-JS is a lightweight JavaScript library for implementing the publish/subscribe pattern. It allows you to create a simple messaging system where you can publish events and subscribe to them, making it easier to manage communication between different parts of your application.

What are pubsub-js's main functionalities?

Publishing Events

This feature allows you to publish events to a specific topic. Other parts of your application can then subscribe to this topic and react to the event.

const PubSub = require('pubsub-js');

// Publish an event
PubSub.publish('MY TOPIC', { message: 'Hello World!' });

Subscribing to Events

This feature allows you to subscribe to a specific topic. When an event is published to this topic, the subscriber function will be called with the event data.

const PubSub = require('pubsub-js');

// Subscribe to an event
const mySubscriber = (msg, data) => {
  console.log(`Message: ${msg}, Data: ${JSON.stringify(data)}`);
};

const token = PubSub.subscribe('MY TOPIC', mySubscriber);

Unsubscribing from Events

This feature allows you to unsubscribe from a specific topic using the token received when you subscribed. This is useful for cleaning up and preventing memory leaks.

const PubSub = require('pubsub-js');

// Unsubscribe from an event
PubSub.unsubscribe(token);

Other packages similar to pubsub-js

Keywords

FAQs

Package last updated on 10 Feb 2014

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