keenstore

1.1.1 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i keenstore

Weekly Downloads

13

Version

1.1.1

License

ISC

Unpacked Size

4.64 kB

Total Files

6

Last publish

Collaborators

  • axtk