I read through the redux-actions
tutorial, and am confused by their use of (what I believe to be) destructuring. Below is an example (increment
& decrement
are both functions returned by the createAction
function).
const { createAction, handleActions } = window.ReduxActions;
const reducer = handleActions(
{
[increment]: state => ({ ...state, counter: state.counter + 1 }),
[decrement]: state => ({ ...state, counter: state.counter - 1 })
},
defaultState
);
Here's another example of this being used:
const { createActions, handleActions, combineActions } = window.ReduxActions;
const reducer = handleActions(
{
[combineActions(increment, decrement)]: (
state,
{ payload: { amount } }
) => {
return { ...state, counter: state.counter + amount };
}
},
defaultState
);
Can somebody explain what's happening in those lines? In simplified terms, I just see {[function]: () => ({})}
, and don't understand what this does.