Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitef4acb7

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 parent72d7655 commitef4acb7

File tree

3 files changed

+17
-41
lines changed

3 files changed

+17
-41
lines changed

‎package.json‎

Lines changed: 1 addition & 1 deletion
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‎

Lines changed: 14 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import{expect}from'chai';
2-
importidentityfrom'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+
constreducer=handleAction(type,(state)=>state,defaultState);
101+
constaction={
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-
constreducer=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-
constreducer=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-
constreducer=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‎

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

1110
exportdefaultfunctionhandleAction(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
returnstate;
3429
}
3530

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp