staten
Vanilla state management (633 bytes!)
Why?
Some state management libraries are complex and opinionated, while others are tightly coupled to a specific framework. Staten is simple and familiar. It uses functional concepts to manage state and is extremely light-weight (633 bytes).
Basic Usage
; ; ; store.subscribe store.actions.increment; store.getState; //=> { count: 1 }
Actions
Actions are at the root of Staten. An action is a function that returns a copy of the updated state. Notice how we only have to return the properties we want to update in the new state object.
;
Some actions need access to the current state. For this we add another function that takes state
as an argument.
;
Async actions
To handle async data fetching, use the actions
argument to call another action.
;
Subscriptions
When state changes, your app needs to know about it. Using the subscribe
method, you can attach as many subscriptions as you'd like.
; store.subscribeconsole.logstate;store.subscribe