Choices/assets/scripts/src/reducers/options.js

28 lines
693 B
JavaScript
Raw Normal View History

const options = (state = [], action) => {
switch (action.type) {
2016-04-12 15:31:07 +02:00
case 'ADD_OPTION':
// Add object to items array
let newState = [...state, {
id: parseInt(action.id),
value: action.value,
disabled: false,
selected: false
}];
return newState;
case 'SELECT_OPTION':
return state.map((option) => {
if(option.id === parseInt(action.id)) {
option.selected = action.selected;
}
return option;
});
default:
return state;
}
}
export default options;