feat(object-reducers): replace will now shallow merge with initial state
This commit is contained in:
parent
751ccdd629
commit
4ff81b4035
|
@ -17,8 +17,8 @@ describe('ObjectReducer', () => {
|
|||
it('reducer should return the state if the payload is undefined', () => {
|
||||
expect(replace.reducer({ foo: 1 }, undefined)).toEqual({ foo: 1 });
|
||||
});
|
||||
it('reducer should return the new state', () => {
|
||||
expect(replace.reducer({ foo: 1 }, { foo: 2 })).toEqual({ foo: 2 });
|
||||
it('reducer should return the new state combined with the initial state', () => {
|
||||
expect(replace.reducer({ foo: 1, bar: 3 }, { foo: 2 }, { foo: 1, bar: 5 })).toEqual({ foo: 2, bar: 5 });
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -73,9 +73,12 @@ export const DEFAULT_SHAPE_BEHAVIORS: ShapeReducerBehaviorsConfig = {
|
|||
validate: false,
|
||||
},
|
||||
replace: {
|
||||
reducer(state, payload) {
|
||||
reducer(state, payload, initialState) {
|
||||
if (!payload) return state;
|
||||
return payload;
|
||||
return {
|
||||
...initialState,
|
||||
...payload,
|
||||
};
|
||||
},
|
||||
validate: true,
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue