em-observable
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

Observable

Make a variable observable through accessors

Usage

1. Create observable

let myObservable = new Observable<T>();

the observable can optionally be initialized with a value

2. Add some observers

Observers are consumer lamdas.

you can add observers at any time. if you save their tokens, you can also remove them again

let myToken = myObservable((value : T)=>{...});

these observers will be notified the next time the value changes

3. Alter the value

myObservable.set(something : T) : T;

now all observers will be notified if the value has changed.

if the new value is identical to the old value, subscribers will not be notified.

4. Inspect the value

myObservable.get() : T;

will return the current internal value

Package Sidebar

Install

npm i em-observable

Weekly Downloads

0

Version

1.0.0

License

GPL-3.0

Unpacked Size

16.6 kB

Total Files

11

Last publish

Collaborators

  • emdiet