Skip to content

axtk/keenstore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

keenstore

Zero-dependency data store offering subscription to changes

Installation

npm i keenstore

Usage

import { Store } from 'keenstore';

let store = new Store({ value: 42 });

// Read the data in the store
store.getState(); // > { value: 42 }

// Subscribe to updates in the store and add a callback for each
// update via `store.setState()`
store.onUpdate((nextState, prevState) => {
    console.log(nextState.value, prevState.value);
});

// Update the data in the store and trigger the update callbacks
store.setState({ value: 100 });
// To unsubscribe an update callback from the store use the
// returned value of the `store.onUpdate()` method
let unsubscribe = store.onUpdate((nextState, prevState) => {
    console.log(nextState.value, prevState.value);
});

unsubscribe();

See also

About

Zero-dependency data store offering subscription to changes

Resources

Stars

Watchers

Forks

Packages

No packages published