new-pubsub

Minimalistic Pubsub Library

npm install new-pubsub
8 downloads in the last week
42 downloads in the last month

Minimalistic Pubsub Library.

$ npm install pubsub

Usage

Creates and returns a new Pubsub object.

onReady = pubsub()

onReady(function(a, b){ //  oronReady.subscribe
    console.log('A: %s, B: %s', a, b)
})

onReady.publish(3, 4)

unsubscribe

foo = pubsub({ bar: 1 })

function callback(a, b){
    console.log('A: %s, B: %s', a, b)
}

foo.subscribe(callback)
foo.subscribers.length
// => 1

foo.unsubscribe(callback)
foo.subscribers.length
// => 0

subscribe.once

foo.subscribe.once(function(update){

    update
    // => 3.14

})

foo.publish(3.14)
foo.publish(156)

npm loves you