1.0.1 • Published 10 years ago

courier v1.0.1

Weekly downloads
3
License
MIT
Repository
github
Last release
10 years ago

Courier Publish/Subscribe Module

Usage - Functional Style

var publish = require("courier").publish,
    subscribe = require("courier").subscribe,
    undeliverable = requireq("courier").undeliverable,
    obj = {a:1};

// add a subscriber function to an object
subscribe(obj, function(msg) {});

// publish a message to all object subscribers
publish(obj, "Foo!");

// add a subscription channel by passing in extra argument
subscribe(obj, "FOO", function(msg) {});

// similarly, add an extra publish argument to publish to a channel
publish(obj, "FOO", "Foo!");

// when not subscribed published messages go nowhere
publish(obj, "BAR", "Bar!");    // no subscribers called

// unless you want them to fallback as an undeliverable message
undeliverable(obj, function(ch, msg) {});

Usage - Object Style

var courier = require("courier").courier,
    obj = {a:1};

// call the courier function to add a Courier to the object
courier(obj);

// subscribe using the object courier
obj.courier.subscribe(function(msg) {});

// subscribe to a courier channel
obj.courier.subscribe("FOO", function(msg) {});

// publish using the object courier
obj.courier.publish("Foo!");

// publish to a courier channel
obj.courier.publish("FOO", "Foo!");

// setup an undeliverable recipient
obj.courier.undeliverable(function(ch, msg) {});
1.0.1

10 years ago

1.0.0

10 years ago

0.8.0

11 years ago

0.7.1

12 years ago

0.7.0

12 years ago

0.9.0

13 years ago

0.6.0

13 years ago

0.5.1

13 years ago

0.5.0

13 years ago