@@ -4,7 +4,8 @@ import isPlainObject from './utils/isPlainObject'
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 => {
@@ -64,22 +70,30 @@ function assertReducerShape(reducers) {
6470 if ( typeof initialState === 'undefined' ) {
6571 throw new Error (
6672 `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.`
7177 )
7278 }
7379
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 ( '.' )
7587 if ( typeof reducer ( undefined , { type } ) === 'undefined' ) {
7688 throw new Error (
7789 `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.`
8397 )
8498 }
8599 } )
@@ -137,7 +151,12 @@ export default function combineReducers(reducers) {
137151 }
138152
139153 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+ )
141160 if ( warningMessage ) {
142161 warning ( warningMessage )
143162 }
0 commit comments