iom

๐Ÿฃ๐Ÿ”ค๐Ÿš€Tiny, simple, over-powered state management

View the Project on GitHub okaysoftware/iom

API

Store

Create a store

The initial state likely should describe the full intended shape of the store

Parameters

Examples

const INITIAL_STATE = { on: false };
const store = new Store(INITIAL_STATE);

constructor

Create a store

Parameters

subscribe

Add a subscriber to the store

Subscribers are called with the current state A. when they are first passed to the subscribe method and B. whenever an action is executed on the store via the update method

Parameters

Examples

const subscriber = console.log;
const cancel = store.subscribe(subscriber);
// do some things
cancel();

Returns Function A function that cancels the subscription when called

update

Perform an action on the state and update all subscribers with the new state

Actions passed to the update method are called with the current state and return the new state

Parameters

Examples

const toggleOn = state => ({ ...state, on: !state.on });
store.update(toggleOn);