Skip to content

Instantly share code, notes, and snippets.

@rizedr
Created January 21, 2017 12:51
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 rizedr/bcfeaefb2a6082355b9b75a3b5e5fac1 to your computer and use it in GitHub Desktop.
Save rizedr/bcfeaefb2a6082355b9b75a3b5e5fac1 to your computer and use it in GitHub Desktop.
Store actions
import * as types from 'constants/products';
import { fetchAllProducts } from 'api/shopify';
function load() {
return {
type: types.LOAD,
};
}
function loadSuccess(items) {
return {
type: types.LOAD_SUCCESS,
items
};
}
function loadFail(error) {
return {
type: types.LOAD_FAIL,
error
};
}
export function getProducts() {
return dispatch => {
dispatch(load());
fetchAllProducts()
.then(products => {
console.log('actions.getProducts()', products);
dispatch(loadSuccess(products));
})
.catch(error => {
dispatch(loadFail(error));
});
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment