我正在从事由React,Redux和Redux-thunk组成的业余项目。
我现在有3个减速器:
在动作创建者内部,我必须按特定顺序分派多个动作。 我需要将某种数据从第二个acton传递到第三个动作。所以我这样做了:
Actions.js
export const deleteAttacker = id => {
return (dispatch) => {
dispatch({
type: DELETE_ATTACKER,
payload: {
id
}
});
updateDefenders(id, dispatch)
.then(data => dispatch({
type: COMBINATIONS_DELETE_ATTACKER,
payload: {
id,
data,
}
}));
};
};
export const updateDefenders = (id, dispatch) => {
return new Promise((resolve) => {
dispatch({
type: UPDATE_DEFENDERS,
payload: {
id,
resolve
}
});
});
}
Reducers/Defenders.js
...
case UPDATE_DEFENDERS: {
const data = [];
...
// push new elements into the 'data' array
// update the newState object
action.payload.resolve({ data });
// Return the data array, so I can pass that array to the third action.
// Is it a bad thing to do...?
return {
...newState
};
}
...
我的问题:可以在我的reducer内调用resolve方法吗?还是坏事,我应该以其他方式解决我的问题?
谢谢您的建议!