0.0.3 • Published 9 years ago

watch-notify v0.0.3

Weekly downloads
28
License
-
Repository
github
Last release
9 years ago

Watch notify

The omnipresent publish subscribe design pattern. The observers are called in the same order that they are added. If an observer throws an error when executed, the exception is caught and the execution continue to the next one.

Installation

npm install watch-notify

How to use

Require and initialize watch-notify:

var watchNotify = require("watch-notify");

var watchNotify = new WatchNotify();

Watch on a specific topic:

var handle = watchNotify.watch("topic", function handler(message) {
  // this === scope
}, scope /* optional */);

The topic can also be a number:

var handle = watchNotify.watch(1337, function handler() { ... });

Notify on a specific topic:

watchNotify.notify("topic", "hi!");

Several types can be given to notify:

watchNotify.notify("topic", "message1", "message2", anObject, ...);

Remove an observer:

watchNotify.unwatch(handle);

Observe only once. The handler will be called once and then removed, so any new message on topic won't trigger it.

var handle = watchNotify.once("topic", function handler() { ... });

Remove the handler before it's even called for the first time:

watchNotify.unwatch(handle);

CHANGELOG

0.0.3 - 7 APR 2015

  • console.error when an observer throws an error to help with debugging

LICENSE

MIT