Skip to content

Commit 3d5f1ce

Browse files
danawoodmantimche
authored andcommitted
Fix typeof call to return a proper value
1 parent 2ab6068 commit 3d5f1ce

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default (...args) => {
1010
}
1111

1212
return (prevState, value, ...args) => {
13-
const prevStateIsUndefined = typeof (prevState === 'undefined');
13+
const prevStateIsUndefined = typeof prevState === 'undefined';
1414
const valueIsUndefined = typeof value === 'undefined';
1515

1616
if (prevStateIsUndefined && valueIsUndefined && initialState) {

test/index.test.js

+19
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,22 @@ test('no initialState supplied + undefined state: initial state defined by first
8686

8787
expect(reducerAB(undefined, 3)).toEqual({ A: 12, B: 2 });
8888
});
89+
90+
test('actions should progressively update state', () => {
91+
const reducerA = (state, action) => {
92+
if (action.type === 'A') return { ...state, a: true };
93+
return state;
94+
};
95+
const reducerB = (state, action) => {
96+
if (action.type === 'B') return { ...state, b: true };
97+
return state;
98+
};
99+
const initial = { a: false, b: false };
100+
const combined = reduceReducers(reducerA, reducerB, initial);
101+
102+
let state = combined(undefined, { type: 'A' });
103+
expect(state).toEqual({ a: true, b: false });
104+
105+
state = combined(state, { type: 'B' });
106+
expect(state).toEqual({ a: true, b: true });
107+
});

0 commit comments

Comments
 (0)