我正在寻找一种更好的方法来使用redux来塑造我的减速器状态。现在我就是这种情况,就像CRUD一样。
export const isFetchingExternalAction = composeAsyncReducer({
start: FETCH_EXTERNAL_REQUEST,
done: FETCH_EXTERNAL_SUCCESS,
fail: FETCH_EXTERNAL_FAILED
});
export const isFetchingList = composeAsyncReducer({
start: FETCH_LIST_REQUEST,
done: FETCH_LIST_SUCCESS,
fail: FETCH_LIST_FAILED
});
export const isFetchingDetails = composeAsyncReducer({
start: FETCH_DETAILS_REQUEST,
done: FETCH_DETAILS_SUCCESS,
fail: FETCH_DETAILS_FAILED
});
export const isCreating = composeAsyncReducer({
start: CREATE_REQUEST,
done: CREATE_SUCCESS,
fail: CREATE_FAILED
});
export const isUpdating = composeAsyncReducer({
start: UPDATE_REQUEST,
done: UPDATE_SUCCESS,
fail: UPDATE_FAILED
});
export const isDeleting = composeAsyncReducer({
start: DELETE_REQUEST,
done: DELETE_SUCCESS,
fail: DELETE_FAILED
});
export const errors = (state = Map(), action) {
switch (action.type) {
case CREATE_SUCCESS:
case UPDATE_SUCCESS:
return Map();
case CREATE_FAILED:
case UPDATE_FAILED:
return fromJS(action.error);
default:
return state;
}
}
export default combineReducers({
isFetching,
isFetchingList,
isCreating,
isUpdating,
isDeleting,
errors
});
这允许我通过这样的事情来查询:
const mapStateToProps = (state) => ({
isCreating: state.isCreating,
isUpdatingCreating: state.isUpdating
});
我唯一担心的是,这只允许处理一个实体。
用户转到第A页: //我们从页面A获取详细信息。所以isFetchingDetails将返回true。
但是如果我们在获取A的同时转到第B页。我们将遇到麻烦。因为A仍在处理中。那我们怎么解决呢?
谢谢!