@@ -4,7 +4,8 @@ import warning from './utils/warning'
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 => {
@@ -62,22 +68,28 @@ function assertReducerShape(reducers) {
62
68
if ( typeof initialState === 'undefined' ) {
63
69
throw new Error (
64
70
`Reducer "${ key } " returned undefined during initialization. ` +
65
- `If the state passed to the reducer is undefined, you must ` +
66
- `explicitly return the initial state. The initial state may ` +
67
- `not be undefined. If you don't want to set a value for this reducer, ` +
68
- `you can use null instead of undefined.`
71
+ `If the state passed to the reducer is undefined, you must ` +
72
+ `explicitly return the initial state. The initial state may ` +
73
+ `not be undefined. If you don't want to set a value for this reducer, ` +
74
+ `you can use null instead of undefined.`
69
75
)
70
76
}
71
77
72
- const type = '@@redux/PROBE_UNKNOWN_ACTION_' + Math . random ( ) . toString ( 36 ) . substring ( 7 ) . split ( '' ) . join ( '.' )
78
+ const type =
79
+ '@@redux/PROBE_UNKNOWN_ACTION_' +
80
+ Math . random ( )
81
+ . toString ( 36 )
82
+ . substring ( 7 )
83
+ . split ( '' )
84
+ . join ( '.' )
73
85
if ( typeof reducer ( undefined , { type } ) === 'undefined' ) {
74
86
throw new Error (
75
87
`Reducer "${ key } " returned undefined when probed with a random type. ` +
76
- `Don't try to handle ${ ActionTypes . INIT } or other actions in "redux/*" ` +
77
- `namespace. They are considered private. Instead, you must return the ` +
78
- `current state for any unknown actions, unless it is undefined, ` +
79
- `in which case you must return the initial state, regardless of the ` +
80
- `action type. The initial state may not be undefined, but can be null.`
88
+ `Don't try to handle ${ ActionTypes . INIT } or other actions in "redux/*" ` +
89
+ `namespace. They are considered private. Instead, you must return the ` +
90
+ `current state for any unknown actions, unless it is undefined, ` +
91
+ `in which case you must return the initial state, regardless of the ` +
92
+ `action type. The initial state may not be undefined, but can be null.`
81
93
)
82
94
}
83
95
} )
@@ -135,7 +147,12 @@ export default function combineReducers(reducers) {
135
147
}
136
148
137
149
if ( process . env . NODE_ENV !== 'production' ) {
138
- const warningMessage = getUnexpectedStateShapeWarningMessage ( state , finalReducers , action , unexpectedKeyCache )
150
+ const warningMessage = getUnexpectedStateShapeWarningMessage (
151
+ state ,
152
+ finalReducers ,
153
+ action ,
154
+ unexpectedKeyCache
155
+ )
139
156
if ( warningMessage ) {
140
157
warning ( warningMessage )
141
158
}
0 commit comments