Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
A very small Pub/Sub implementation in CoffeeScript
CoffeeScript
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
src
test
.gitignore
README.md

README.md

Coffee PubSub

A very simple implementation of the Pub/Sub (or Observer) pattern in CoffeeScript.

How to Use

Create a new instance:

myApp = new Pubsub

Add a subscription:

someFunc = ->
  console.log "foo"

myApp.sub "someId", "eventTitle", someFunc

Publish events:

myApp.pub "eventTitle"

Send extra info with those events:

someFunc = (data) ->
  console.log(data)

myApp.sub "elem1", "event1", someFunc
myApp.pub "event1", { foo: bar }

And unsubscribe:

myApp.unSub "elem1", "event1"

Tests

Unit tests are done with Mocha. Install with:

npm install -g mocha

Clone the repo, cd into it and:

npm install chai

Then run

mocha --compilers coffee:coffee-script -R spec
Something went wrong with that request. Please try again.