Last active
October 7, 2017 19:43
-
-
Save vzaidman/2dce474ccbb8ca2489217e5ef3852e20 to your computer and use it in GitHub Desktop.
Using an async action creator in a vanilla reducer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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