courier
Variant of the publish/subscribe pattern.
Last updated 6 years ago by rremer .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install courier 
SYNC missed versions from official npm registry.

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) {});

Current Tags

  • 1.0.1                                ...           latest (6 years ago)

2 Versions

  • 1.0.1                                ...           6 years ago
  • 1.0.0                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (2)

Copyright 2014 - 2016 © taobao.org |