From 4ff81b4035e2d82ba662ca312dfac463f76581db Mon Sep 17 00:00:00 2001 From: Kai Moseley Date: Tue, 17 Oct 2017 17:28:25 +0100 Subject: [PATCH] feat(object-reducers): replace will now shallow merge with initial state --- src/reducers/__tests__/objectReducer.test.js | 4 ++-- src/reducers/objectReducer.js | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/reducers/__tests__/objectReducer.test.js b/src/reducers/__tests__/objectReducer.test.js index 2a60c52..cfca9cf 100644 --- a/src/reducers/__tests__/objectReducer.test.js +++ b/src/reducers/__tests__/objectReducer.test.js @@ -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 }); }); }); diff --git a/src/reducers/objectReducer.js b/src/reducers/objectReducer.js index 324341d..9d589a9 100644 --- a/src/reducers/objectReducer.js +++ b/src/reducers/objectReducer.js @@ -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, }