a simple observable data
npm install kltk-observable
-
import with esm
import { observable } from 'kltk-observable';
-
create a observable
const initial = {}; const store = observable(initial);
-
subscribe/unsubscribe observable state changes
const listener = (state) => { console.log('store changed', state); }; const unsubscribe = store.subscribe(listener); setTimeout(() => { // unsubscribe with subscribe return unsubscribe(); // unsubscribe with store // store.unsubscribe(listener); });