Store
new Store(
initialState,
{
actions,
getters
}
);
- 1.
initialState
: Object or function that defines the initial state - 2.actions : Object that groups the actions of the state
- 3.getters : Object that creates virtual values of the state.
async function *myAction(state, optionalParam){
const stateUpdates = await logicAsync(optionalParam);
return {
...(yield),
...stateUpdates
}
}
getters are just functions that compute state.
const total = (state)=>state.a + state.b;
Subscribes to state changes, example:
const off = store.on((state)=>{
console.log(state.loading);
});
off(); // remove the subscription
Clone the state and define a new state for it.
Last modified 10mo ago