@@ -2,11 +2,11 @@ import { ActionTypes } from './createStore'
2
2
import isPlainObject from 'lodash/isPlainObject'
3
3
import warning from './utils/warning'
4
4
5
- var NODE_ENV = typeof process !== 'undefined' ? process . env . NODE_ENV : 'development'
5
+ const NODE_ENV = typeof process !== 'undefined' ? process . env . NODE_ENV : 'development'
6
6
7
7
function getUndefinedStateErrorMessage ( key , action ) {
8
- var actionType = action && action . type
9
- var actionName = actionType && `"${ actionType . toString ( ) } "` || 'an action'
8
+ const actionType = action && action . type
9
+ const actionName = actionType && `"${ actionType . toString ( ) } "` || 'an action'
10
10
11
11
return (
12
12
`Given action ${ actionName } , reducer "${ key } " returned undefined. ` +
@@ -15,8 +15,8 @@ function getUndefinedStateErrorMessage(key, action) {
15
15
}
16
16
17
17
function getUnexpectedStateShapeWarningMessage ( inputState , reducers , action , unexpectedKeyCache ) {
18
- var reducerKeys = Object . keys ( reducers )
19
- var argumentName = action && action . type === ActionTypes . INIT ?
18
+ const reducerKeys = Object . keys ( reducers )
19
+ const argumentName = action && action . type === ActionTypes . INIT ?
20
20
'preloadedState argument passed to createStore' :
21
21
'previous state received by the reducer'
22
22
@@ -36,7 +36,7 @@ function getUnexpectedStateShapeWarningMessage(inputState, reducers, action, une
36
36
)
37
37
}
38
38
39
- var unexpectedKeys = Object . keys ( inputState ) . filter ( key =>
39
+ const unexpectedKeys = Object . keys ( inputState ) . filter ( key =>
40
40
! reducers . hasOwnProperty ( key ) &&
41
41
! unexpectedKeyCache [ key ]
42
42
)
@@ -57,8 +57,8 @@ function getUnexpectedStateShapeWarningMessage(inputState, reducers, action, une
57
57
58
58
function assertReducerSanity ( reducers ) {
59
59
Object . keys ( reducers ) . forEach ( key => {
60
- var reducer = reducers [ key ]
61
- var initialState = reducer ( undefined , { type : ActionTypes . INIT } )
60
+ const reducer = reducers [ key ]
61
+ const initialState = reducer ( undefined , { type : ActionTypes . INIT } )
62
62
63
63
if ( typeof initialState === 'undefined' ) {
64
64
throw new Error (
@@ -69,7 +69,7 @@ function assertReducerSanity(reducers) {
69
69
)
70
70
}
71
71
72
- var type = '@@redux/PROBE_UNKNOWN_ACTION_' + Math . random ( ) . toString ( 36 ) . substring ( 7 ) . split ( '' ) . join ( '.' )
72
+ const type = '@@redux/PROBE_UNKNOWN_ACTION_' + Math . random ( ) . toString ( 36 ) . substring ( 7 ) . split ( '' ) . join ( '.' )
73
73
if ( typeof reducer ( undefined , { type } ) === 'undefined' ) {
74
74
throw new Error (
75
75
`Reducer "${ key } " returned undefined when probed with a random type. ` +
@@ -100,10 +100,10 @@ function assertReducerSanity(reducers) {
100
100
* passed object, and builds a state object with the same shape.
101
101
*/
102
102
export default function combineReducers ( reducers ) {
103
- var reducerKeys = Object . keys ( reducers )
104
- var finalReducers = { }
105
- for ( var i = 0 ; i < reducerKeys . length ; i ++ ) {
106
- var key = reducerKeys [ i ]
103
+ const reducerKeys = Object . keys ( reducers )
104
+ const finalReducers = { }
105
+ for ( let i = 0 ; i < reducerKeys . length ; i ++ ) {
106
+ const key = reducerKeys [ i ]
107
107
108
108
if ( NODE_ENV !== 'production' ) {
109
109
if ( typeof reducers [ key ] === 'undefined' ) {
@@ -115,13 +115,14 @@ export default function combineReducers(reducers) {
115
115
finalReducers [ key ] = reducers [ key ]
116
116
}
117
117
}
118
- var finalReducerKeys = Object . keys ( finalReducers )
118
+ const finalReducerKeys = Object . keys ( finalReducers )
119
119
120
+ let unexpectedKeyCache
120
121
if ( NODE_ENV !== 'production' ) {
121
- var unexpectedKeyCache = { }
122
+ unexpectedKeyCache = { }
122
123
}
123
124
124
- var sanityError
125
+ let sanityError
125
126
try {
126
127
assertReducerSanity ( finalReducers )
127
128
} catch ( e ) {
@@ -134,21 +135,21 @@ export default function combineReducers(reducers) {
134
135
}
135
136
136
137
if ( NODE_ENV !== 'production' ) {
137
- var warningMessage = getUnexpectedStateShapeWarningMessage ( state , finalReducers , action , unexpectedKeyCache )
138
+ const warningMessage = getUnexpectedStateShapeWarningMessage ( state , finalReducers , action , unexpectedKeyCache )
138
139
if ( warningMessage ) {
139
140
warning ( warningMessage )
140
141
}
141
142
}
142
143
143
- var hasChanged = false
144
- var nextState = { }
145
- for ( var i = 0 ; i < finalReducerKeys . length ; i ++ ) {
146
- var key = finalReducerKeys [ i ]
147
- var reducer = finalReducers [ key ]
148
- var previousStateForKey = state [ key ]
149
- var nextStateForKey = reducer ( previousStateForKey , action )
144
+ let hasChanged = false
145
+ const nextState = { }
146
+ for ( let i = 0 ; i < finalReducerKeys . length ; i ++ ) {
147
+ const key = finalReducerKeys [ i ]
148
+ const reducer = finalReducers [ key ]
149
+ const previousStateForKey = state [ key ]
150
+ const nextStateForKey = reducer ( previousStateForKey , action )
150
151
if ( typeof nextStateForKey === 'undefined' ) {
151
- var errorMessage = getUndefinedStateErrorMessage ( key , action )
152
+ const errorMessage = getUndefinedStateErrorMessage ( key , action )
152
153
throw new Error ( errorMessage )
153
154
}
154
155
nextState [ key ] = nextStateForKey
0 commit comments