add reducer action for epoch mutation in place

This commit is contained in:
Sorrel Bri 2019-12-04 21:22:12 -08:00
parent a29d7177dd
commit ab02f945c6
2 changed files with 28 additions and 0 deletions

View file

@ -20,4 +20,18 @@ describe('Epochs', () => {
const action = {type: 'ADD_EPOCH', value: { name: 'epoch 2', changes: []}};
expect(stateReducer(state, action)).toEqual({...state, epochs: [...state.epochs, action.value]})
})
it('epoch name mutation returns new epochs list with mutation', () => {
const firstAction = {type: 'ADD_EPOCH', value: { name: 'epoch 2', changes: []}};
const secondAction = {type: 'SET_EPOCH', value: { index: 0, name: 'proto-lang'}};
const secondState = stateReducer(state, firstAction);
expect(stateReducer(secondState, secondAction)).toEqual(
{...state,
epochs: [
{name: 'proto-lang', changes: []},
{name: 'epoch 2', changes: []}
]
}
);
});
});

View file

@ -57,6 +57,20 @@ const stateReducer = (state, action) => {
return {...state, epochs: [...state.epochs, newEpoch]}
}
case 'SET_EPOCH': {
let mutatedEpochs = state.epochs;
let index = [action.value.index]
mutatedEpochs[index].name = action.value.name
? action.value.name
: mutatedEpochs[index].name;
mutatedEpochs[index].changes = action.value.changes
? action.value.changes
: mutatedEpochs[index].changes;
return {...state, epochs: [...mutatedEpochs]}
}
case 'ADD_FEATURE': {
let positivePhones = action.value.positivePhones || [];
let negativePhones = action.value.negativePhones || [];