1.1.0 • Published 7 years ago

obzervable-js v1.1.0

Weekly downloads
4
License
MIT
Repository
github
Last release
7 years ago

obzervable-js

A small mixin to make your objects' constructors observable.


Install

npm install obzervable-js

Usage

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
1.1.0

7 years ago

1.0.0

7 years ago