Skip to content

Instantly share code, notes, and snippets.

@dewey92
Last active April 22, 2018 10:23
Show Gist options
  • Select an option

  • Save dewey92/a2d8a009877015f17d453e11c6ecbec1 to your computer and use it in GitHub Desktop.

Select an option

Save dewey92/a2d8a009877015f17d453e11c6ecbec1 to your computer and use it in GitHub Desktop.
const AsyncState = {
idle: 'idle',
loading: 'loading',
loaded: 'loaded',
error: 'error'
}
const initialState = {
user: {
data: {},
asyncState: AsyncState.idle,
},
}
export default (state = initialState, action) => {
switch (action.type) {
case 'GET_USER_REQUEST':
return {
...state,
user: {
...state.user,
asyncState: AsyncState.loading
}
}
case 'GET_USER_SUCCESS':
return {
...state,
user: {
...state.user,
data: action.payload.result,
asyncState: AsyncState.loaded
}
}
case 'GET_USER_FAILED':
return {
...state,
user: {
...state.user,
asyncState: AsyncState.error,
error: action.payload.error
}
}
default:
return state
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment