watch-notify
Advanced tools
Comparing version 0.0.1 to 0.0.2
{ | ||
"name": "watch-notify", | ||
"description": "The omnipresent publish subscribe design pattern.", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"homepage": "https://github.com/flams/watch-notify", | ||
@@ -6,0 +6,0 @@ "licenses": [ |
Watch notify | ||
============= | ||
The omnipresent publish subscribe design pattern. | ||
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. | ||
@@ -16,9 +16,56 @@ Installation | ||
Require watch-notify: | ||
Require and initialize watch-notify: | ||
```js | ||
var watchNotify = require("watch-notify"); | ||
var watchNotify = new WatchNotify(); | ||
``` | ||
Watch on a specific topic: | ||
```js | ||
var handle = watchNotify.watch("topic", function handler(message) { | ||
// this === scope | ||
}, scope /* optional */); | ||
``` | ||
The topic can also be a number: | ||
```js | ||
var handle = watchNotify.watch(1337, function handler() { ... }); | ||
``` | ||
Notify on a specific topic: | ||
```js | ||
watchNotify.notify("topic", "hi!"); | ||
``` | ||
Several types can be given to notify: | ||
```js | ||
watchNotify.notify("topic", "message1", "message2", anObject, ...); | ||
``` | ||
Remove an observer: | ||
```js | ||
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. | ||
```js | ||
var handle = watchNotify.once("topic", function handler() { ... }); | ||
``` | ||
Remove the handler before it's even called for the first time: | ||
```js | ||
watchNotify.unwatch(handle); | ||
``` | ||
LICENSE | ||
@@ -25,0 +72,0 @@ ======= |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7488
74