Skip to content

Instantly share code, notes, and snippets.

@clintonhalpin
Created February 24, 2016 23:32
Show Gist options
  • Save clintonhalpin/bcb5d159f0edbddf2a63 to your computer and use it in GitHub Desktop.
Save clintonhalpin/bcb5d159f0edbddf2a63 to your computer and use it in GitHub Desktop.
// 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