mirror of
https://github.com/Choices-js/Choices.git
synced 2024-06-27 09:50:10 +02:00
26 lines
669 B
JavaScript
26 lines
669 B
JavaScript
// Array of choices
|
|
const choices = (state = [], action) => {
|
|
switch (action.type) {
|
|
case 'ADD_ITEM':
|
|
// Add object to items array
|
|
return [...state, {
|
|
id: parseInt(action.id),
|
|
value: action.value,
|
|
element: action.element,
|
|
active: true
|
|
}];
|
|
|
|
case 'REMOVE_ITEM':
|
|
// Remove item from items array
|
|
return state.filter(function(item) {
|
|
if(item.id !== parseInt(action.id)) {
|
|
return item;
|
|
}
|
|
});
|
|
|
|
default:
|
|
return state;
|
|
}
|
|
}
|
|
|
|
export default choices |