@@ -4,7 +4,8 @@ import warning from './utils/warning'
44
55function getUndefinedStateErrorMessage ( key , action ) {
66 const actionType = action && action . type
7- const actionDescription = ( actionType && `action "${ String ( actionType ) } "` ) || 'an action'
7+ const actionDescription =
8+ ( actionType && `action "${ String ( actionType ) } "` ) || 'an action'
89
910 return (
1011 `Given ${ actionDescription } , reducer "${ key } " returned undefined. ` +
@@ -13,11 +14,17 @@ function getUndefinedStateErrorMessage(key, action) {
1314 )
1415}
1516
16- function getUnexpectedStateShapeWarningMessage ( inputState , reducers , action , unexpectedKeyCache ) {
17+ function getUnexpectedStateShapeWarningMessage (
18+ inputState ,
19+ reducers ,
20+ action ,
21+ unexpectedKeyCache
22+ ) {
1723 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'
2128
2229 if ( reducerKeys . length === 0 ) {
2330 return (
@@ -29,15 +36,14 @@ function getUnexpectedStateShapeWarningMessage(inputState, reducers, action, une
2936 if ( ! isPlainObject ( inputState ) ) {
3037 return (
3138 `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 ] +
3340 `". Expected argument to be an object with the following ` +
3441 `keys: "${ reducerKeys . join ( '", "' ) } "`
3542 )
3643 }
3744
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 ]
4147 )
4248
4349 unexpectedKeys . forEach ( key => {
@@ -62,22 +68,28 @@ function assertReducerShape(reducers) {
6268 if ( typeof initialState === 'undefined' ) {
6369 throw new Error (
6470 `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.`
6975 )
7076 }
7177
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 ( '.' )
7385 if ( typeof reducer ( undefined , { type } ) === 'undefined' ) {
7486 throw new Error (
7587 `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.`
8193 )
8294 }
8395 } )
@@ -135,7 +147,12 @@ export default function combineReducers(reducers) {
135147 }
136148
137149 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+ )
139156 if ( warningMessage ) {
140157 warning ( warningMessage )
141158 }
0 commit comments