Created
July 13, 2017 06:47
-
-
Save jtulk/27f2c30a053a075d67c2d18e5ad3e8a4 to your computer and use it in GitHub Desktop.
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 { ACTIONS } from './actions'; | |
const initialState = { | |
content: {}, | |
error: null, | |
isFetching: false, | |
lastFetched: 0 | |
} | |
const myContentReducer = (state = initialState, action = {}) => { | |
const { error, payload, type } = action; | |
switch (type) { | |
case ACTIONS.error: { | |
return { | |
...state, | |
error, | |
isFetching: false | |
}; | |
} | |
case ACTIONS.startFetch: { | |
return { | |
...state, | |
isFetching: true | |
}; | |
} | |
case ACTIONS.update: { | |
return { | |
...state, | |
content: payload, | |
error: null, | |
isFetching: false, | |
lastFetched: Date.now() | |
}; | |
} | |
default: { | |
return state; | |
} | |
} | |
}; | |
export default myContentReducer; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment