Skip to content

Instantly share code, notes, and snippets.

@adnaan
Created November 2, 2016 04:54
Show Gist options
  • Save adnaan/226afb213ea7268e8dcebf4f5c8da0b9 to your computer and use it in GitHub Desktop.
Save adnaan/226afb213ea7268e8dcebf4f5c8da0b9 to your computer and use it in GitHub Desktop.
reducers: {
query(state) {
return { ...state, loading: true, };
},
querySuccess(state, { payload }) {
return { ...state, loading: false, list: payload };
},
vote(state) {
return { ...state, loading: true };
},
voteSuccess(state, { payload }) {
const newList = state.list.map(product => {
if (product.id === payload) {
return { ...product, vote:product.vote + 1 };
} else {
return product;
}
});
return { ...state, list: newList, loading: false };
},
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment