Jupter's goal is to have a simple and small publish & subscribe API that is super-powerful at the same time. Every method in Jupiter is chainable.
jupiter(String || Array || Object-literal)
Initiates jupiter and accepts one of:
This method can be cached using a variable, or used directly every time.
Returns:
parent.children
structureObject-literal schema:
{
'parent': ['child', '...etc']
}
Each parent topic (property) in the object must map to an Array of child topics. Each parent/child is then chainable.
.sub([key, ]callback[, context])
Subscribe a function to a topic.
key
- optional. A key for use with unsubscribing a specific callback at any time.callback
- required. The callback function to be called.context
- optional. The context with which to call the callback.Note: key
and context
can be optionally set, as long as they remain in the order of key, callback, context
:
.sub('myKey', myCallback) // key, callback
.sub(myCallback, this) // callback, context
Now that you have subscribers setup, any time a topic is published to, the subscriber will be called.
.pub([arguments])
Publish (broadcast) the topic to all subscribers. Accepts unlimited optional arguments.
.unsub([keyName])
Unsubscribe all callbacks from the topic, or when passing a key name (from the .sub()
method), unsubscribe just one callback.
The callback(s) will no longer be called when a topic is published to.
.list(callback[, true])
Returns all callbacks for the provided topic. Optionally pass true
to return the entire callback Object. Does not publish.