A simple Observable implementation in JavaScript.
npm install --save @dobschal/observableObserve values and get notified when they change:
import{Observable}from'@dobschal/observable';constcount=Observable(5);count.subscribe(value=>{console.log(value);});count.set(10);// will trigger the subscription and log 10count.value=15;// will trigger the subscription and log 15Watch computed values:
import{Computed,Observable}from'@dobschal/observable';constcount=Observable(5);constmultiplied=Computed(()=>count.value*2);multiplied.subscribe(value=>{console.log(value);});