new-pubsub

Minimalistic Pubsub Library

Minimalistic Pubsub Library.

$ npm install pubsub

Creates and returns a new Pubsub object.

onReady = pubsub()
 
onReady(function(ab){ //  oronReady.subscribe 
    console.log('A: %s, B: %s', a, b)
})
 
onReady.publish(3, 4)
foo = pubsub({ bar: 1 })
 
function callback(ab){
    console.log('A: %s, B: %s', a, b)
}
 
foo.subscribe(callback)
foo.subscribers.length
// => 1 
 
foo.unsubscribe(callback)
foo.subscribers.length
// => 0 
foo.subscribe.once(function(update){
 
    update
    // => 3.14 
 
})
 
foo.publish(3.14)
foo.publish(156)