Skip to content

Commit ef4acb7

Browse files
committed
Remove FSA check in handleAction(s)
With #141 we have made other libraries incompatible with redux-actions and it resulted to an unexpected behavior (#164, #167). If an action is not a FSA, handleAction should not handle it and just pass it to the next reducer. This fix will remove the FSA check to support Non-FSA. Closes #164, #167
1 parent 72d7655 commit ef4acb7

File tree

3 files changed

+17
-41
lines changed

3 files changed

+17
-41
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@
5050
"eslint-config-airbnb-base": "^1.0.3",
5151
"eslint-plugin-import": "^1.5.0",
5252
"eslint-watch": "^2.1.13",
53+
"flux-standard-action": "^1.0.0",
5354
"mocha": "^2.2.5",
5455
"rimraf": "^2.5.3",
5556
"webpack": "^1.13.1"
5657
},
5758
"dependencies": {
58-
"flux-standard-action": "^1.0.0",
5959
"invariant": "^2.2.1",
6060
"lodash": "^4.13.1",
6161
"reduce-reducers": "^0.1.0"

src/__tests__/handleAction-test.js

+14-33
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { expect } from 'chai';
2-
import identity from 'lodash/identity';
32
import { handleAction, createAction, createActions, combineActions } from '../';
43

54
describe('handleAction()', () => {
@@ -96,6 +95,20 @@ describe('handleAction()', () => {
9695
counter: 7
9796
});
9897
});
98+
99+
it('should not throw and return state when action is non-FSA', () => {
100+
const reducer = handleAction(type, (state) => state, defaultState);
101+
const action = {
102+
foo: {
103+
bar: 'baz'
104+
}
105+
};
106+
107+
expect(reducer(undefined, action)).not.to.throw;
108+
expect(reducer(undefined, action)).to.deep.equal({
109+
counter: 0
110+
});
111+
});
99112
});
100113
});
101114

@@ -239,36 +252,4 @@ describe('handleAction()', () => {
239252
.to.deep.equal({ number: 3 });
240253
});
241254
});
242-
243-
describe('with invalid actions', () => {
244-
it('should throw a descriptive error when the action object is missing', () => {
245-
const reducer = handleAction(createAction('ACTION_1'), identity, {});
246-
expect(
247-
() => reducer(undefined)
248-
).to.throw(
249-
Error,
250-
'The FSA spec mandates an action object with a type. Try using the createAction(s) method.'
251-
);
252-
});
253-
254-
it('should throw a descriptive error when the action type is missing', () => {
255-
const reducer = handleAction(createAction('ACTION_1'), identity, {});
256-
expect(
257-
() => reducer(undefined, {})
258-
).to.throw(
259-
Error,
260-
'The FSA spec mandates an action object with a type. Try using the createAction(s) method.'
261-
);
262-
});
263-
264-
it('should throw a descriptive error when the action type is not a string or symbol', () => {
265-
const reducer = handleAction(createAction('ACTION_1'), identity, {});
266-
expect(
267-
() => reducer(undefined, { type: false })
268-
).to.throw(
269-
Error,
270-
'The FSA spec mandates an action object with a type. Try using the createAction(s) method.'
271-
);
272-
});
273-
});
274255
});

src/handleAction.js

+2-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import isNil from 'lodash/isNil';
55
import isUndefined from 'lodash/isUndefined';
66
import includes from 'lodash/includes';
77
import invariant from 'invariant';
8-
import { isFSA } from 'flux-standard-action';
98
import { ACTION_TYPE_DELIMITER } from './combineActions';
109

1110
export default function handleAction(actionType, reducer = identity, defaultState) {
@@ -24,12 +23,8 @@ export default function handleAction(actionType, reducer = identity, defaultStat
2423
: [reducer.next, reducer.throw].map(aReducer => (isNil(aReducer) ? identity : aReducer));
2524

2625
return (state = defaultState, action) => {
27-
invariant(
28-
isFSA(action),
29-
'The FSA spec mandates an action object with a type. Try using the createAction(s) method.'
30-
);
31-
32-
if (!includes(actionTypes, action.type.toString())) {
26+
const { type } = action;
27+
if (type && !includes(actionTypes, type.toString())) {
3328
return state;
3429
}
3530

0 commit comments

Comments
 (0)