mirror of
https://github.com/Choices-js/Choices.git
synced 2024-06-08 17:02:33 +02:00
28 lines
693 B
JavaScript
28 lines
693 B
JavaScript
const options = (state = [], action) => {
|
|
switch (action.type) {
|
|
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; |