我通读了redux-actions
教程,并且对他们使用(我认为是)解构感到困惑。下面是一个示例(increment
&decrement
都是函数返回的两个createAction
函数)。
const { createAction, handleActions } = window.ReduxActions;
const reducer = handleActions(
{
[increment]: state => ({ ...state, counter: state.counter + 1 }),
[decrement]: state => ({ ...state, counter: state.counter - 1 })
},
defaultState
);
这是另一个使用此方法的示例:
const { createActions, handleActions, combineActions } = window.ReduxActions;
const reducer = handleActions(
{
[combineActions(increment, decrement)]: (
state,
{ payload: { amount } }
) => {
return { ...state, counter: state.counter + amount };
}
},
defaultState
);
有人可以解释这些行中发生了什么吗?简而言之,我只看到{[function]: () => ({})}
,不明白这是做什么的。