Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Minimalistic Pubsub Implementation
branch: master
Failed to load latest commit information.
.gitignore hello kitties
.travis.yml Update .travis.yml
README.md Update README.md
index.js better test coverage
package.json 1.0.1
perf.js faster, better
test.js fix for new prova

README.md

pubsub Build Status

Library for creating individual events with a minimalistic API.

Install

$ npm install pubsub

Usage

onReady = pubsub()

onReady(function(a, b, c){ // shortcut to: onReady.subscribe
    console.log(a, b, c)
    // => 3, 4, 1
})

onReady.publish(3, 4, 1)

You can optionally, you can pass pubsub() an object to mix the interfaces:

foo = pubsub({ value: 12345 })

foo.subscribe(function () {

  foo.value
  // => 3.14
  // => 158
})

foo.value = 314
foo.publish()

foo.value = 158
foo.publish()

API

subscribe(fn)

foo.subscribe(function(update){

    update
    // => 3.14
    // => 156
    // => { last: true }

})

foo.publish(3.14)
foo.publish(156)
foo.publish({ last: true })

subscribe.once(fn)

foo.subscribe.once(function(update){

    update
    // => 3.14

})

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

unsubscribe(fn)

unsubscribe.once(fn)

Something went wrong with that request. Please try again.