@dobschal/observable
v1.0.6
Published
Turn any variable into an observable object.
Maintainers
Readme
Observable
A simple Observable implementation in JavaScript.
Installation
npm install --save @dobschal/observableUsage
Observe values and get notified when they change:
import { Observable } from '@dobschal/observable';
const count = Observable(5);
count.subscribe(value => {
console.log(value);
});
count.set(10); // will trigger the subscription and log 10
count.value = 15; // will trigger the subscription and log 15Watch computed values:
import { Computed, Observable } from '@dobschal/observable';
const count = Observable(5);
const multiplied = Computed(() => count.value * 2);
multiplied.subscribe(value => {
console.log(value);
});