subscribe/unsubscribe multiple pubsubs at once
JavaScript
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
.gitignore
.travis.yml
README.md
index.js
package.json
test.js

README.md

subscribe Build Status

Subscribe to multiple pub/subs.

Install

$ npm install subscribe

Usage

pubsub = require('pubsub')
subscribe = require('subscribe')

a = pubsub()
b = pubsub()
c = pubsub()

subscribe(a, b, c, function(updates){

    updates[0].pubsub
    // => a.onUpdate

    updates[0].params
    // => 3, 4

    updates[1].pubsub
    // => c.onUpdate

    updates[1].params
    // => 5, 6

})

a.publish(3, 4)
c.publish(5, 6)

Subscribing For Once

subscribe.once fires the callback once all the pubsubs publish, for one time.

a = pubsub()
b = pubsub()
c = pubsub()

once(a, b, c, function(){

    console.log('a, b, and c published')

})

a.publish(3, 4)
b.publish(5, 6)
c.publish(7, 8)