New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

nano-pubsub

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

nano-pubsub

Zero dependency, tiny (<0.5 kb) publish/subscribe

  • 3.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
222K
increased by3.61%
Maintainers
1
Weekly downloads
 
Created

What is nano-pubsub?

nano-pubsub is a lightweight publish-subscribe (pub/sub) library for JavaScript. It allows you to create a simple event-driven architecture where you can publish events and subscribe to them, making it easier to manage communication between different parts of your application.

What are nano-pubsub's main functionalities?

Creating a PubSub instance

This code demonstrates how to create a new instance of the PubSub class from the nano-pubsub package. This instance will be used to manage event subscriptions and publications.

const PubSub = require('nano-pubsub');
const pubsub = new PubSub();

Subscribing to an event

This code shows how to subscribe to an event named 'eventName'. The callback function will be called whenever the event is published, and it will receive the published data as an argument.

const subscription = pubsub.subscribe('eventName', (data) => {
  console.log('Event received:', data);
});

Publishing an event

This code demonstrates how to publish an event named 'eventName' with some data. All subscribers to this event will receive the data.

pubsub.publish('eventName', { key: 'value' });

Unsubscribing from an event

This code shows how to unsubscribe from an event. After calling unsubscribe, the callback function will no longer be called when the event is published.

subscription.unsubscribe();

Other packages similar to nano-pubsub

Keywords

FAQs

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