Skip to content

Instantly share code, notes, and snippets.

@Jessica7
Created June 14, 2016 14:35
Show Gist options
  • Select an option

  • Save Jessica7/98f7829f2fa348f0bdc68febf7e67517 to your computer and use it in GitHub Desktop.

Select an option

Save Jessica7/98f7829f2fa348f0bdc68febf7e67517 to your computer and use it in GitHub Desktop.
reducer
import * as ACTIONS from '../constants/products';
const initialState = {
items: [],
allCheked : []
};
const sortByPrice = (a, b) => {
var productA = parseInt(a.priceCash);
var productB = parseInt(b.priceCash);
return (productA >= productB) ? -1 : 1;
};
function products(state = initialState, action) {
switch(action.type) {
case ACTIONS.INJECT_PRODUCTS: {
return {
...state,
items: action.items
};
};
case ACTIONS.FILTER_PRICE: {
const sorted = state.items.sort(sortByPrice);
if (action.key == 'lowest price') {
sorted.reverse();
}
return {
...state,
items: sorted
};
};
case ACTIONS.FITLER_CATEGORY: {
const newList = state.allChecked;
newList.push("palavra");
return {
...state,
allChecked: newList
}
}
default: {
return state;
};
}
}
export default products;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment