Skip to content

Instantly share code, notes, and snippets.

@puzzfuzz
Created January 29, 2018 22:36
Show Gist options
  • Save puzzfuzz/1b2c303dc3eaff5b183a7cdd07d3eb92 to your computer and use it in GitHub Desktop.
Save puzzfuzz/1b2c303dc3eaff5b183a7cdd07d3eb92 to your computer and use it in GitHub Desktop.
/** src/reducers/cart.js **/
const initialState = {
...window.shopifyData.cart, // Rehydrate cart state from server data
isUpdating: false
};
const cart = (state = initialState, action) => { // Bootstrap initial state
switch (action.type) {
case 'CART_IS_UPDATING': {
return {
...state,
isUpdating: true
};
}
case 'CART_UPDATED': {
const { newCart } = action;
return {
...state,
...newCart,
isUpdating: false
};
}
default:
return state;
}
};
export default cart;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment