Created
February 24, 2016 23:32
-
-
Save clintonhalpin/bcb5d159f0edbddf2a63 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// actions/index.js | |
import * as collectionActionTypes from './collection.actions.js'; | |
const actions = { | |
...collectionActionTypes | |
} | |
export default actions | |
// actions/collection.actions.js | |
import api from './../util/api'; | |
const COLLECTION_REQUEST = 'COLLECTION_REQUEST'; | |
const COLLECTION_SUCCESS = 'COLLECTION_SUCCESS'; | |
const COLLECTION_FAILURE = 'COLLECTION_FAILURE'; | |
function recieveCollection(json) { | |
return { | |
type: COLLECTION_SUCCESS, | |
data: json, | |
receivedAt: Date.now() | |
} | |
} | |
function fetchCollection(req) { | |
return dispatch => { | |
return api.fetchCollection(req) | |
.then(response => response.json()) | |
.then(json => dispatch(recieveCollection(json))) | |
} | |
} | |
export function fetchCollectionIfNeeded(req) { | |
return (dispatch, getState) => { | |
return dispatch(fetchCollection(req)); | |
} | |
} | |
export { | |
COLLECTION_REQUEST, | |
COLLECTION_FAILURE, | |
COLLECTION_SUCCESS, | |
fetchCollectionIfNeeded | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment