Slim javascript observer pattern implementation.
npm install slim-observerJavascript (typescript) implementation of observer pattern on less then 100 rows.
It provides just o few most common functions and minified version is smaller then 2kB.


!GitHub package version
slim-observer is available on NPM and Bower. To install it, type:
$ npm install slim-observer
or
$ bower install slim-observer
You can also use it within the browser; install via npm/bower and use the slim-observer.min.js file found within the download. For example:
``html`example.html
See full example in
#### Functions
Basic usage
`js
// create observable subject
var observable = new SlimObserver.Subject();
// create first listener
observable.subscribe(function(newValue){
alert(newValue);
});
// create second listener
observable.subscribe(function(newValue){
console.log(newValue);
});
observable.next('hello'); // emit value to all listeners
observable.next('world'); // emit another value
`
Get last emitted value
`js`
observable.getLast();
Create subject with initial value
`js`
var observable = new SlimObserver.Subject('initial value');
New subscriber with all history values replay.
`js`
observable.replayAndSubscribe(function(newValue){
console.log(newValue);
});
Unsubscribe existing listener.
`js
var observable = new SlimObserver.Subject();
var subscriber = observable.subscribe(function(newValue){
alert(newValue);
});
subscriber.unsubscribe();
`
Emitting only unique values (if new value is different).
`js`
observable.nextUnique(123).nextUnique(123); // emits value to subscribers only once
folder. Maps included.
`
npm run build
`$3
Tests framework used are: mocha & chai.
`
npm test
`Testing with coverage:
`
nyc npm test
``