Skip to content

Instantly share code, notes, and snippets.

@indigoviolet
Created October 4, 2017 08:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save indigoviolet/a8f04996495fd6ef14a656769e720da4 to your computer and use it in GitHub Desktop.
Save indigoviolet/a8f04996495fd6ef14a656769e720da4 to your computer and use it in GitHub Desktop.
fin blog embed
// adapted from http://redux.js.org/docs/advanced/AsyncActions.html#reducersjs
import {
REQUEST_POSTS,
RECEIVE_POSTS
} from '../actions'
function postsReducer(
state = {
isFetching: false,
items: []
},
action
) {
switch (action.type) {
case REQUEST_POSTS:
return Object.assign({}, state, {
isFetching: true,
didInvalidate: false
})
case RECEIVE_POSTS:
return Object.assign({}, state, {
isFetching: false,
didInvalidate: false,
items: action.posts,
lastUpdated: action.receivedAt
})
default:
return state
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment