Skip to content
/ pubsub Public

A pubsub object for passing around events and callbacks.

License

Notifications You must be signed in to change notification settings

mlaroy/pubsub

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

PubSub

A pubsub object for passing around events and callbacks.

Credit where credit is due: this is an object-based version of Devin's class-based pubsub.

import PubSub from 'path/to/PubSub/';

// Basic example inside a click handler

document.addEventListener('click', event => {
  // extract some data
  const { target } = event;
  
  // trigger an event
  PubSub.trigger('someEvent', target);
});

.
.
.

import PubSub from 'path/to/PubSub/';

// subscribe to the event, and fire a callback
PubSub.on('someEvent', data => {
  // callback function here
  console.log(data); //  => event.target 
});

Follow Me.

About

A pubsub object for passing around events and callbacks.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published