Stateli
Stateli is a state management library borrowing concepts from Vuex but with no reliance on Vue.
- State management using Immutable
- Asynchronous actions are dispatched
- Synchronous state mutations are committed
- Can be used with a single state or modules with individual states
Installation
Install stateli with npm.
$ npm install stateli --save
Usage (javascript)
const StateliStore = ; const someAction = type: 'some_action_name' { // 1) do something const promise = ; // 2) optionally commit to update state promise; // 3) return a promise return promise; }; const someMutation = type: 'some_mutation_name' { // We don't update the state directly but instead we create a shallow copy, // modify the copy and return it. Stateli will then replace the actual // state with the returned copy. const updatedState = ...state val: payload ; return updatedState; }; const someGetter = type: 'some_getter_name' stateval; const initialState = val: '' ; const store = actions: someAction mutations: someMutation getters: someGetter initialState; // dispatch an asynchronous actionstore; // commit a synchronous mutationstore; // get value from getterconst val = store; // access stateconst val = storestateval;
Usage (typescript)
; ; ; ; ;; ; // dispatch an asynchronous actionstore.dispatch'some_action_Name', 'payload_value'; // commit a synchronous mutationstore.commit'some_mutation_name', 'payload_value'; // get value from getter; // access root state;