CommonJS Implementation of the Observer Pattern
JavaScript
Latest commit 37f2b84 Dec 5, 2011 @azer Merge pull request #1 from cybear/master
"undefined" is not a reserved keyword
Failed to load latest commit information.
lib Undefined is not a reserved keyword Dec 5, 2011
test initial commit Feb 11, 2011
README.md readme correction Feb 12, 2011
package.json update package manifest Oct 15, 2011

README.md

observer.js

An implementation of the observer design pattern.

Tested Platforms: V8 (Node)

From NPM

npm install observer

Usage

To create an observation table: var EventBroker = require('observer').EventBroker;

var events = new EventBroker;
events.create('foobar');

events.subscribe('foobar', console.log.bind(console,'observer#1:') );
events.subscribe('foobar', console.log.bind(console,'observer#2:') );

events.publish('foobar',3,14);

// => observer#1, 3, 14
// => observer#2, 3, 14

To create an observable class: var Observable = require('observer').Observable, inherits = require('util').inherits;

function Foobar(){
  Observable.call(this);
  this.create('qux');
}

var f = new Foobar();
f.on('qux', console.log.bind(console, 'observer#3:');
f.events.publish('qux',3,14);

// => observer#3, 3, 14

Testing

node test/test.js