Skip to content

Instantly share code, notes, and snippets.

@vzaidman
Last active October 7, 2017 19:43
Show Gist options
  • Save vzaidman/2dce474ccbb8ca2489217e5ef3852e20 to your computer and use it in GitHub Desktop.
Save vzaidman/2dce474ccbb8ca2489217e5ef3852e20 to your computer and use it in GitHub Desktop.
Using an async action creator in a vanilla reducer
import { fetchProfile } from 'actions'
const initialState = { loading: false }
export const profileReducer = (state = initialState, {type, payload}) => {
switch (type) {
case fetchProfile.TYPE:
// handling action type 'FETCH_PROFILE@ASYNC_REQUEST'.
return { loading: true }
case fetchProfile.success.TYPE:
// handling action type 'FETCH_PROFILE@ASYNC_SUCCESS'
return { loading: false, data: payload }
case fetchProfile.failure.TYPE:
// handling action type 'FETCH_PROFILE@ASYNC_FAILURE'
return { loading: false, error: payload }
case fetchProfile.progress.TYPE:
// handling action type 'FETCH_PROFILE@ASYNC_PROGRESS'
return { ...state, progress: payload }
default:
return state
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment