import purify from 'redux-purify';
const { actions, reducer } = purify({
increment(state, action) => ({
...state,
counter: state.counter + 1,
}),
decrement(state, action) => ({
...state,
counter: state.counter - 1,
}),
setCounter(state, action, value) => ({
...state,
counter: value,
})
});
const store = createStore(reducer);
store.dispatch(actions.increment());
store.dispatch(actions.decrement());
store.dispatch(actions.setCounter(5));
const initialState = {
sandwichesMade: 0,
};
const { actions, reducer } = purify({
makeASandwich(state, action) => ({
...state,
sandwichesMade: state.sandwichesMade + 1,
}),
}, initialState);
const store = createStore(reducer);
store.dispatch(actions.makeASandwich());
store.dispatch(actions.makeASandwich());
console.log(store.getState());
Note to self: this might not be the worst idea ever.