pbsb
v0.5.1
Published
Yet another PubSub Library.
Readme
Usage
PbSb.sub(event, subscriber, handler)
event
String, event name.
subscriber
Object subscribing the event.
handler
The method name or reference of the subscriber.
Example
var ClassA = function(){ return { callback_function: function(){ return 'foobar'; } } } var a = new A(); PbSb.sub('the_event', a, 'callback_function'); // or PbSb.sub('my_very_first_event', a, a.callback_function);subscriber is optional, so you may calling sub like this
PbSb.sub('my_event', function(){...})PbSb.unsub(event, subscriber, handler)
event
String, event name.
subscriber
Object unsubscribing the event.
handler
The method name or reference of the subscriber.
When all 3 parameters supplied,
PbSbwill unsubscribe the specific matched event handler.If there are only 2 parameters and the second parameter is a function,
PbSbwill only unsubscribe the handler, else,PbSbremoves all subscription to the event from the subscriber.Examples
PbSb.unsub('event1', a, 'foo'); PbSb.unsub('eventB', a); PbSb.unsub('EventX', some_method);PbSb.pub(event, args)
event
String, event name.
args
Array, arguements that will passed to the subscribed callback, optional.
Examples
PbSb.pub('da_event'); PbSb.pub('fruits_coming', ['apple', 'orange']);
To Run Tests
npm install -g mocha
npm test