PS.js
Browser Usage
Minified and unminified versions in the dist folder.
Node.js Usage
npm install dtang-pubsub
Link to NPM page: https://npmjs.org/package/dtang-pubsub
var Evt = ; var ps = ;
Public Methods
publish(topic, [data])
- topic (string) - your custom event name
- data (mixed) optional argument for any data that you would like to be passed with a publication and used in subscriptions.
subscribe(topic, callback, [context])
- topic (string) - your custom event name
- callback (function) - function invoked when topic is published
- context (object) - optional argument for what this will refer to within the callback function. By default, this will point to the current PS instance
- returns a subscription ID to potentially be used in unsubscribing
unsubscribe(subscriptionID)
- subscriptionID (int) - returned from the subscribe method
Examples
var ps = ; var s1 = ps; // 3rd argument will be the context used for the 2nd argument var s2 = ps; ps; ps; // unsubscribes s1 console;