Aug 22, 2017 · 1 min read
I find that example you gave in the beginning of the post quite poor, are people really writing redux code like that?
Because indeed I use some simple middleware but I don't see any cons in doing so.
To me, an action looks something like:
export const EXPORT_CAMPAIGN_CSV = defineAction(‘EXPORT_CAMPAIGN_CSV’)export const fetchCampaignsByUser = () => (dispatch, getState) => dispatch({
type: FETCH_CAMPAIGNS_BY_USER.ACTION,
payload: campaignService.getAll(getState().user.get(‘auth_token’)),
})
And a reducer is just:
export const campaign = createReducer(INITIAL_STATE, {
[FETCH_CAMPAIGNS_BY_USER.FULFILLED]: (state, { payload }) =>
state.mergeDeep(normalize(payload, [campaignSchema]).entities.campaign),
})If the promise fails, it never gets to the .FULFILLEDstate into the reducer, an error reducer will get it and have its payload available under a key named as the action name..
I really don't see redux as verbose as you insist.
