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
This repository was archived by the owner on Jan 23, 2019. It is now read-only.

Commitcde2622

Browse files
Artem Zakharchenkokettanaito
Artem Zakharchenko
authored andcommitted
Create reducer: Implement proper interface
1 parent7ed93eb commitcde2622

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

‎src/createReducer.js‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Iterable, Map, fromJS } from 'immutable';
33
import{ReduxAction,CreateReducerArgs}from'./interfaces';
44

55
constdefaultArgs:CreateReducerArgs={
6-
initialState:{}
6+
actions:[]
77
};
88

99
/**
@@ -17,12 +17,12 @@ export function createReducer(args: CreateReducerArgs = defaultArgs) {
1717
let{ initialState, actions}=args;
1818

1919
if(!actions){
20-
throwError(`Shorthand reducer should have {actions} property specified, but received:${actions}.`);
20+
throwError(`Shorthand reducer should have {actions} property specified.`);
2121
}
2222

23-
return(state:Object,dispatchedAction:ReduxAction)=>{
23+
return(state:Map<String,any>|Object,dispatchedAction:ReduxAction)=>{
2424
/* Convert action to immutable */
25-
constaction=Map(dispatchedAction);
25+
constaction=fromJS(dispatchedAction);
2626
constdispatchedType=action.get('type');
2727

2828
/* Duplicate the state for further changes */
@@ -39,7 +39,11 @@ export function createReducer(args: CreateReducerArgs = defaultArgs) {
3939
constisRegExp=(expectedTypeinstanceofRegExp);
4040

4141
/* Determine if dispatched action type is expected */
42-
constshouldActionPass=isRegExp ?expectedType.test(dispatchedType) :expectedType.includes(dispatchedType);
42+
if(expectedTypeinstanceofRegExp){
43+
varshouldActionPass=expectedType.test(dispatchedType);
44+
}else{
45+
varshouldActionPass=expectedType.includes(dispatchedType);
46+
}
4347

4448
/* Mutate the state once dispatched action type is expected */
4549
if(shouldActionPass){

‎src/interfaces/index.js‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/*@flow */
2+
13
/**
24
* Redux: dispatched action
35
*/
@@ -8,10 +10,12 @@ export interface ReduxAction {
810
/**
911
* Create reducer: arguments
1012
*/
13+
interfaceExpectedActions{
14+
type:String|RegExp,
15+
reducer:Function
16+
};
17+
1118
exportinterfaceCreateReducerArgs{
12-
initialState:Object,
13-
actions?:interfaceExpectedActions{
14-
type:String|RegExp,
15-
reducer:Function
16-
}
19+
initialState?:Object,
20+
actions:Array<ExpectedActions>
1721
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp