Skip to content

kltk/observable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

kltk Observable

a simple observable data

Installtion

npm install kltk-observable

Usage

  1. import with esm

    import { observable } from 'kltk-observable';
  2. create a observable

    const initial = {};
    const store = observable(initial);
  3. 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);
    });

About

a simple observable data & react hooks

Resources

Stars

Watchers

Forks

Packages

No packages published