Socket
Socket
Sign inDemoInstall

@art4/pub-sub

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @art4/pub-sub

Publish-subscribe event pattern


Version published
Weekly downloads
1
Maintainers
1
Install size
14.4 kB
Created
Weekly downloads
 

Readme

Source

Example

import { PubSub, EMIT_GLOBAL } from 'pub-sub';


const pubsub = new PubSub();

const unsubscribeChat = pubsub.on('chat/message', (message) => {
  ...
});
const dialogHandler = (payload) => { ... };
pubsub.on('dialog/opened', dialogHandler);



pubsub.emit('chat/message', 'Hello');
/* Emit event to every subscriber */
pubsub.emit(EMIT_GLOBAL, '[System error]');



/* Remove subscriptions */

unsubscribeChat();

pubsub.off('dialog/opened', dialogHandler); 
/* or remove all subscribers of specific event */
pubsub.off('dialog/opened');

FAQs

Last updated on 31 May 2019

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc