Redux is created with a set of reducers and initial state. Reducers are put into an object where keys are action tags and properties are reducing functions. Each said function will receive a state and action payload (not whole action) and should return new state (optionally - asynchronously, with a Promise).
Redux, like Atom, has unwrap
method that allows for synchronous access to stored value.
Redux::next
should be provided with an object of shape:
{action: ACTION,data: ACTION_DATA}
Consider this example:
const redux = new Redux({addNumber(state, data: number) {return { state: [...state, data] };},async addString(state, data: string) {return {state: [...state, data],effects: [{ type: "success", data: null }]};},success(state) {// this is just for demonstration sake// you should try to make actions without side-effectsconsole.log("🎉 success!");return state;}},new Array<string | number>());​await redux.next({ type: "addNumber", data: 0 });// redux.unwrap() is [0]​await redux.next({ type: "addString", data: "a" });// redux.unwrap() is [0, "a"]