Skip to content

NicoZelaya/pub-sub-library

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PubSubDN

A Pub/Sub library in vanilla JavaScript

PubSubDN is library agnostic. It's implemented only using vanilla JavaScript and it's minimalistic. It was implemented as a self-training phase of the Globant JavaScript Lab, so will not receive too much support. Either way, PubSubDN can get things done.

How to use:

Just include PubSubDN in your code. PubSubDN is compatible with CommonJS or AMD loaders, and of course, with normal JavaScript implementations. Again, just include it in your code and PubSubDN will be available. If you're working with no module loader, it's at the PubSub global.

It offers just the 3 basic functions: Publish, Subscribe and Unsubscribe:

Publish:

PubSub.publish(topic, args); takes two parameters:
topic is a string representing the topic of your message.
args is an optional parameter, it represents the arguments you want the subscribers functions for this topic to receive.
This method will return false if the topic has no subscribers, and this if it was a success, so you can do things like PubSub.publish('Globant').publish('myTopic', 'My Message');

Subscribe:

PubSub.subscribe(topic, fn); takes two parameters:
topic is a string representing the topic you want to subscribe.
fn is the function to be executed any time a Publisher sends a message with the topic of this subscription.
This method will return a token that you should store, because it's used for unsubscribing.

Unsubscribe:

PubSub.unsubscribe(token); takes only one parameter:
token this is the token you received at the subscribing stage.
This method will return the same token when unsubscribing a subscriber, or false if the subscriber was not found.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published