mirror of
https://github.com/Choices-js/Choices.git
synced 2024-05-17 04:56:34 +02:00
36 lines
860 B
JavaScript
36 lines
860 B
JavaScript
const choice = (state = [], action) => {
|
|
console.log('Choice', action);
|
|
switch(action.type) {
|
|
case 'ADD_VALUE':
|
|
return {
|
|
value: action.value,
|
|
element: action.element,
|
|
active: true
|
|
};
|
|
case 'REMOVE_VALUE':
|
|
return Object.assign({}, state, {
|
|
active: false
|
|
});
|
|
default:
|
|
return state;
|
|
}
|
|
}
|
|
|
|
const choices = (state = {}, action) => {
|
|
console.log('Choices', action);
|
|
switch(action.type) {
|
|
case 'ADD_VALUE':
|
|
return [
|
|
...state,
|
|
choice(undefined, action)
|
|
]
|
|
case 'REMOVE_VALUE':
|
|
return state.map(t =>
|
|
choice(t, action)
|
|
)
|
|
default:
|
|
return state;
|
|
}
|
|
}
|
|
|
|
export default choices |