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.
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 using 2 mechanisms: Watchers and Observers.
Watchers
Watchers are simple functions that get called when the observable value changes.
They receive 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 that use other Observables to determine their values.
When the observable changes then observers are updated.
const observable = new Observable(20); const computedObservable = new ComputedObservable(() => observable.value * 2); 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