@@ -2,8 +2,6 @@ import { ActionTypes } from '../createStore';
2
2
import isPlainObject from '../utils/isPlainObject' ;
3
3
import mapValues from '../utils/mapValues' ;
4
4
import pick from '../utils/pick' ;
5
- import invariant from 'invariant' ;
6
- import warning from 'warning' ;
7
5
8
6
function getErrorMessage ( key , action ) {
9
7
var actionType = action && action . type ;
@@ -19,17 +17,15 @@ function verifyStateShape(initialState, currentState) {
19
17
var reducerKeys = Object . keys ( currentState ) ;
20
18
21
19
if ( reducerKeys . length === 0 ) {
22
- warning (
23
- false ,
20
+ console . error (
24
21
'Store does not have a valid reducer. Make sure the argument passed ' +
25
22
'to combineReducers is an object whose values are reducers.'
26
23
) ;
27
24
return ;
28
25
}
29
26
30
27
if ( ! isPlainObject ( initialState ) ) {
31
- warning (
32
- false ,
28
+ console . error (
33
29
'initialState has unexpected type of "' +
34
30
( { } ) . toString . call ( initialState ) . match ( / \s ( [ a - z | A - Z ] + ) / ) [ 1 ] +
35
31
'". Expected initialState to be an object with the following ' +
@@ -42,12 +38,13 @@ function verifyStateShape(initialState, currentState) {
42
38
key => reducerKeys . indexOf ( key ) < 0
43
39
) ;
44
40
45
- warning (
46
- unexpectedKeys . length === 0 ,
47
- `Unexpected ${ unexpectedKeys . length > 1 ? 'keys' : 'key' } ` +
48
- `"${ unexpectedKeys . join ( '", "' ) } " in initialState will be ignored. ` +
49
- `Expected to find one of the known reducer keys instead: "${ reducerKeys . join ( '", "' ) } "`
50
- ) ;
41
+ if ( unexpectedKeys . length > 0 ) {
42
+ console . error (
43
+ `Unexpected ${ unexpectedKeys . length > 1 ? 'keys' : 'key' } ` +
44
+ `"${ unexpectedKeys . join ( '", "' ) } " in initialState will be ignored. ` +
45
+ `Expected to find one of the known reducer keys instead: "${ reducerKeys . join ( '", "' ) } "`
46
+ ) ;
47
+ }
51
48
}
52
49
53
50
/**
@@ -72,24 +69,26 @@ export default function combineReducers(reducers) {
72
69
73
70
Object . keys ( finalReducers ) . forEach ( key => {
74
71
var reducer = finalReducers [ key ] ;
75
- invariant (
76
- typeof reducer ( undefined , { type : ActionTypes . INIT } ) !== 'undefined' ,
77
- `Reducer "${ key } " returned undefined during initialization. ` +
78
- `If the state passed to the reducer is undefined, you must ` +
79
- `explicitly return the initial state. The initial state may ` +
80
- `not be undefined.`
81
- ) ;
72
+ if ( typeof reducer ( undefined , { type : ActionTypes . INIT } ) === 'undefined' ) {
73
+ throw new Error (
74
+ `Reducer "${ key } " returned undefined during initialization. ` +
75
+ `If the state passed to the reducer is undefined, you must ` +
76
+ `explicitly return the initial state. The initial state may ` +
77
+ `not be undefined.`
78
+ ) ;
79
+ }
82
80
83
81
var type = Math . random ( ) . toString ( 36 ) . substring ( 7 ) . split ( '' ) . join ( '.' ) ;
84
- invariant (
85
- typeof reducer ( undefined , { type } ) !== 'undefined' ,
86
- `Reducer "${ key } " returned undefined when probed with a random type. ` +
87
- `Don't try to handle ${ ActionTypes . INIT } or other actions in "redux/*" ` +
88
- `namespace. They are considered private. Instead, you must return the ` +
89
- `current state for any unknown actions, unless it is undefined, ` +
90
- `in which case you must return the initial state, regardless of the ` +
91
- `action type. The initial state may not be undefined.`
92
- ) ;
82
+ if ( typeof reducer ( undefined , { type } ) === 'undefined' ) {
83
+ throw new Error (
84
+ `Reducer "${ key } " returned undefined when probed with a random type. ` +
85
+ `Don't try to handle ${ ActionTypes . INIT } or other actions in "redux/*" ` +
86
+ `namespace. They are considered private. Instead, you must return the ` +
87
+ `current state for any unknown actions, unless it is undefined, ` +
88
+ `in which case you must return the initial state, regardless of the ` +
89
+ `action type. The initial state may not be undefined.`
90
+ ) ;
91
+ }
93
92
} ) ;
94
93
95
94
var defaultState = mapValues ( finalReducers , ( ) => undefined ) ;
@@ -98,10 +97,9 @@ export default function combineReducers(reducers) {
98
97
return function combination ( state = defaultState , action ) {
99
98
var finalState = mapValues ( finalReducers , ( reducer , key ) => {
100
99
var newState = reducer ( state [ key ] , action ) ;
101
- invariant (
102
- typeof newState !== 'undefined' ,
103
- getErrorMessage ( key , action )
104
- ) ;
100
+ if ( typeof newState === 'undefined' ) {
101
+ throw new Error ( getErrorMessage ( key , action ) ) ;
102
+ }
105
103
return newState ;
106
104
} ) ;
107
105
0 commit comments