slim-observer
Javascript (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.
Installation
slim-observer
is available on NPM and Bower. To install it, type:
$ npm install slim-observer
or
$ bower install slim-observer
Usage
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:
See full example in example.html
Functions
Basic usage
// create observable subjectvar observable = ; // create first listenerobservable; // create second listenerobservable; observablenext'hello'; // emit value to all listenersobservablenext'world'; // emit another value
Get last emitted value
observable;
Create subject with initial value
var observable = 'initial value';
New subscriber with all history values replay.
observable;
Unsubscribe existing listener.
var observable = ; var subscriber = observable; subscriber;
Emitting only unique values (if new value is different).
observable; // emits value to subscribers only once
Building tools
Build
Transpile TS code to JS in dist/
folder. Maps included.
npm run build
Unit Test
Tests framework used are: mocha & chai.
npm test
Testing with coverage:
nyc npm test
License
This project seed is licensed as Public Domain. Therefore, do whatever you want including changing the license for your needs in your project. More specifically, it was licensed as CC0 (Creative Commons 0) to further improve the freedom of a Public Domain Licence in context where it is not applicable.