Choices/assets/scripts/src/reducers/index.js
2016-03-30 15:04:21 +01:00

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