@art4/pub-sub
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

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');

Readme

Keywords

none

Package Sidebar

Install

npm i @art4/pub-sub

Weekly Downloads

2

Version

1.0.1

License

MIT

Unpacked Size

14.8 kB

Total Files

14

Last publish

Collaborators

  • art4