Skip to content

Instantly share code, notes, and snippets.

@msikma
Created February 9, 2017 13:38
Show Gist options
  • Save msikma/fbe9d7fe756c68df7670fa2585adc995 to your computer and use it in GitHub Desktop.
Save msikma/fbe9d7fe756c68df7670fa2585adc995 to your computer and use it in GitHub Desktop.
// Here's a simple example reducer, a simplified form of what we're using.
// It loads a list of employees.
import * as types from '../actions/action-types'
const initialState = {
hasData: false,
isLoading: false,
entityList: [],
error: null
}
const reducer = (state = initialState, action) => {
switch (action.type) {
case types.EMPLOYEES_FETCH_BEGIN:
return {
...state,
isLoading: true,
error: null
}
case types.EMPLOYEES_FETCH_SUCCEEDED:
return {
...state,
hasData: true,
isLoading: false,
entityList: action.payload.entityList,
error: null
}
case types.EMPLOYEES_FETCH_FAILED:
return {
...state,
isLoading: false,
error: action.payload.message
}
default:
return state
}
}
export default reducer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment