1.1.0 • Published 9 years ago
obzervable-js v1.1.0
obzervable-js
A small mixin to make your objects' constructors observable.
Install
npm install obzervable-jsUsage
Just extend the mixin with your favourite method:
var Observable = require('obzervable-js');
var MyObservable = extendWithYourFavouriteMethod(function() {
	setTimeout(function(that) {
		that._notifyObservers('an-event', {foo: 'bar'});
	}, 2000, this);
}, Observable);
var anObservable = new MyObservable();
anObservable.subscribe('an-event', function(optionalData) {
	console.log('an-event happened', optionalData);
});##Methods
.subscribe(String event, Function callback).unsubscribe(String event, Function callback)._notifyObservers(String event, [data1, [data2], ...])
Note: the wildcard (
*) event will be triggered on any event.
Run tests:
npm test