Any valid javascript value.
Initial value of the observable.
List of ComputedObservables that need to be updated when value changes.
List of WatcherFunctions that get run when the observable value changes.
Current value of the observable.
Safely invoke the watchers registered on this observable.
New value of the observer.
Old value of the observer.
Iterates over observers and recalculates their values.
Add a new ComputedObservable to be observed.
ComputedObservable to be observed.
Stop observing a ComputedObservable.
ComputedObservable to stop observing.
Remove a WatcherFunction from the watchers list.
WatcherFunction to be removed.
Method used to update the value property.
New value of the observable.
Add a WatcherFunction to be called when value changes.
WatcherFunction to be called on value change.
Generated using TypeDoc
A Observable is a value that can be observed for changes.
This observation can happen in two forms: Watchers and Observers.
Watchers
Watchers are simple functions that get called when the observable value changes.
They receives the new and old value of the observable as arguments.
const observable = new Observable(20); observable.watch((value, oldValue) => { console.log(value, oldValue); }); observable.update(15); // output: 15 20
Observers
Observers are ComputedObservables.
When the observable changes then the observers are updated.
const observable = new Observable(20); const computedObservable = new ComputedObservable(() => observable.value * 2); computedObservable.update(computedObservable.evaluate()); console.log(computedObservable.value); // output: 40 observable.observe(computedObservable); // Since the computed observable is now 'observed' it will get updated when the observable changes. observable.update(15); console.log(computedObservable.value); // output: 30