๐ฃ๐ค๐Tiny, simple, over-powered state management
Create a store
The initial state likely should describe the full intended shape of the store
Parameters
state
State Examples
const INITIAL_STATE = { on: false };
const store = new Store(INITIAL_STATE);
Create a store
Parameters
state
State 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
subscriber
Subscriber Examples
const subscriber = console.log;
const cancel = store.subscribe(subscriber);
// do some things
cancel();
Returns Function A function that cancels the subscription when called
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
action
Action Examples
const toggleOn = state => ({ ...state, on: !state.on });
store.update(toggleOn);