Skip to content

Instantly share code, notes, and snippets.

@KensoDev
Last active August 29, 2016 18:45
Show Gist options
  • Select an option

  • Save KensoDev/ce591a0d2d2ee134800db715e7e1c02c to your computer and use it in GitHub Desktop.

Select an option

Save KensoDev/ce591a0d2d2ee134800db715e7e1c02c to your computer and use it in GitHub Desktop.
import * as actionTypes from '../../constants/actionTypes';
const initialState = {
selected: ['Hotel'],
}
export default function itemTypeReducer(state = initialState, action) {
let selected = state.selected.slice(0);
let newArray = null;
if (action.type == actionTypes.TOGGLE_ITEM_TYPE) {
if (selected.indexOf(action.itemType) >= 0) {
newArray = selected.filter((item) => {
return item != action.itemType
});
return {
selected: newArray
}
} else {
newArray = selected.concat([action.itemType])
return {
selected: newArray
}
}
}
return state;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment