feat(object-reducer): object reducer reset payloads can be provided
The payload for an object reset action will be applied on top of the default state of an object.
This commit is contained in:
parent
877d3646d5
commit
89ca4bf8fa
|
@ -27,6 +27,14 @@ describe('ObjectReducer', () => {
|
|||
it('reducer should return the initial state', () => {
|
||||
expect(reset.reducer({ foo: 1 }, undefined, { foo: 2 })).toEqual({ foo: 2 });
|
||||
});
|
||||
|
||||
it('reducer should apply the payload (if an object) to the store over the default state', () => {
|
||||
expect(reset.reducer({ foo: 23, bar: 4 }, { foo: 1 }, { foo: 4, bar: 5 })).toEqual({foo: 1, bar: 5});
|
||||
});
|
||||
|
||||
it('reducer should return initial state if the payload is not an object', () => {
|
||||
expect(reset.reducer({ foo: 23, bar: 4 }, 'nope!', { foo: 4, bar: 5 })).toEqual({foo: 4, bar: 5});
|
||||
});
|
||||
});
|
||||
|
||||
describe('update', () => {
|
||||
|
|
|
@ -67,7 +67,8 @@ export const DEFAULT_SHAPE_BEHAVIORS: ShapeReducerBehaviorsConfig = {
|
|||
},
|
||||
reset: {
|
||||
reducer(state, payload, initialState) {
|
||||
return initialState;
|
||||
if (!isObject(payload)) return initialState;
|
||||
return { ...initialState, ...payload };
|
||||
},
|
||||
validate: false,
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue