@@ -4,7 +4,8 @@ import isPlainObject from './utils/isPlainObject'
4
4
5
5
function getUndefinedStateErrorMessage ( key , action ) {
6
6
const actionType = action && action . type
7
- const actionDescription = ( actionType && `action "${ String ( actionType ) } "` ) || 'an action'
7
+ const actionDescription =
8
+ ( actionType && `action "${ String ( actionType ) } "` ) || 'an action'
8
9
9
10
return (
10
11
`Given ${ actionDescription } , reducer "${ key } " returned undefined. ` +
@@ -13,11 +14,17 @@ function getUndefinedStateErrorMessage(key, action) {
13
14
)
14
15
}
15
16
16
- function getUnexpectedStateShapeWarningMessage ( inputState , reducers , action , unexpectedKeyCache ) {
17
+ function getUnexpectedStateShapeWarningMessage (
18
+ inputState ,
19
+ reducers ,
20
+ action ,
21
+ unexpectedKeyCache
22
+ ) {
17
23
const reducerKeys = Object . keys ( reducers )
18
- const argumentName = action && action . type === ActionTypes . INIT ?
19
- 'preloadedState argument passed to createStore' :
20
- 'previous state received by the reducer'
24
+ const argumentName =
25
+ action && action . type === ActionTypes . INIT
26
+ ? 'preloadedState argument passed to createStore'
27
+ : 'previous state received by the reducer'
21
28
22
29
if ( reducerKeys . length === 0 ) {
23
30
return (
@@ -29,15 +36,14 @@ function getUnexpectedStateShapeWarningMessage(inputState, reducers, action, une
29
36
if ( ! isPlainObject ( inputState ) ) {
30
37
return (
31
38
`The ${ argumentName } has unexpected type of "` +
32
- ( { } ) . toString . call ( inputState ) . match ( / \s ( [ a - z | A - Z ] + ) / ) [ 1 ] +
39
+ { } . toString . call ( inputState ) . match ( / \s ( [ a - z | A - Z ] + ) / ) [ 1 ] +
33
40
`". Expected argument to be an object with the following ` +
34
41
`keys: "${ reducerKeys . join ( '", "' ) } "`
35
42
)
36
43
}
37
44
38
- const unexpectedKeys = Object . keys ( inputState ) . filter ( key =>
39
- ! reducers . hasOwnProperty ( key ) &&
40
- ! unexpectedKeyCache [ key ]
45
+ const unexpectedKeys = Object . keys ( inputState ) . filter (
46
+ key => ! reducers . hasOwnProperty ( key ) && ! unexpectedKeyCache [ key ]
41
47
)
42
48
43
49
unexpectedKeys . forEach ( key => {
@@ -64,22 +70,30 @@ function assertReducerShape(reducers) {
64
70
if ( typeof initialState === 'undefined' ) {
65
71
throw new Error (
66
72
`Reducer "${ key } " returned undefined during initialization. ` +
67
- `If the state passed to the reducer is undefined, you must ` +
68
- `explicitly return the initial state. The initial state may ` +
69
- `not be undefined. If you don't want to set a value for this reducer, ` +
70
- `you can use null instead of undefined.`
73
+ `If the state passed to the reducer is undefined, you must ` +
74
+ `explicitly return the initial state. The initial state may ` +
75
+ `not be undefined. If you don't want to set a value for this reducer, ` +
76
+ `you can use null instead of undefined.`
71
77
)
72
78
}
73
79
74
- const type = '@@redux/PROBE_UNKNOWN_ACTION_' + Math . random ( ) . toString ( 36 ) . substring ( 7 ) . split ( '' ) . join ( '.' )
80
+ const type =
81
+ '@@redux/PROBE_UNKNOWN_ACTION_' +
82
+ Math . random ( )
83
+ . toString ( 36 )
84
+ . substring ( 7 )
85
+ . split ( '' )
86
+ . join ( '.' )
75
87
if ( typeof reducer ( undefined , { type } ) === 'undefined' ) {
76
88
throw new Error (
77
89
`Reducer "${ key } " returned undefined when probed with a random type. ` +
78
- `Don't try to handle ${ ActionTypes . INIT } or other actions in "redux/*" ` +
79
- `namespace. They are considered private. Instead, you must return the ` +
80
- `current state for any unknown actions, unless it is undefined, ` +
81
- `in which case you must return the initial state, regardless of the ` +
82
- `action type. The initial state may not be undefined, but can be null.`
90
+ `Don't try to handle ${
91
+ ActionTypes . INIT
92
+ } or other actions in "redux/*" ` +
93
+ `namespace. They are considered private. Instead, you must return the ` +
94
+ `current state for any unknown actions, unless it is undefined, ` +
95
+ `in which case you must return the initial state, regardless of the ` +
96
+ `action type. The initial state may not be undefined, but can be null.`
83
97
)
84
98
}
85
99
} )
@@ -137,7 +151,12 @@ export default function combineReducers(reducers) {
137
151
}
138
152
139
153
if ( process . env . NODE_ENV !== 'production' ) {
140
- const warningMessage = getUnexpectedStateShapeWarningMessage ( state , finalReducers , action , unexpectedKeyCache )
154
+ const warningMessage = getUnexpectedStateShapeWarningMessage (
155
+ state ,
156
+ finalReducers ,
157
+ action ,
158
+ unexpectedKeyCache
159
+ )
141
160
if ( warningMessage ) {
142
161
warning ( warningMessage )
143
162
}
0 commit comments