add reducer action for epoch mutation in place
This commit is contained in:
parent
a29d7177dd
commit
ab02f945c6
2 changed files with 28 additions and 0 deletions
|
@ -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: []}
|
||||
]
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
|
@ -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 || [];
|
||||
|
|
Loading…
Reference in a new issue