1
1
import type {
2
+ Action ,
3
+ Middleware ,
2
4
Reducer ,
3
5
ReducersMapObject ,
4
- Middleware ,
5
- Action ,
6
- StoreEnhancer ,
7
6
Store ,
7
+ StoreEnhancer ,
8
8
UnknownAction ,
9
9
} from 'redux'
10
10
import {
11
11
applyMiddleware ,
12
- createStore ,
13
- compose ,
14
12
combineReducers ,
13
+ compose ,
14
+ createStore ,
15
15
isPlainObject ,
16
16
} from 'redux'
17
17
import type { DevToolsEnhancerOptions as DevToolsOptions } from './devtoolsExtension'
18
18
import { composeWithDevTools } from './devtoolsExtension'
19
-
19
+ import type { GetDefaultEnhancers } from './getDefaultEnhancers'
20
+ import { buildGetDefaultEnhancers } from './getDefaultEnhancers'
20
21
import type {
21
- ThunkMiddlewareFor ,
22
22
GetDefaultMiddleware ,
23
+ ThunkMiddlewareFor ,
23
24
} from './getDefaultMiddleware'
24
25
import { buildGetDefaultMiddleware } from './getDefaultMiddleware'
25
26
import type {
26
27
ExtractDispatchExtensions ,
27
- ExtractStoreExtensions ,
28
28
ExtractStateExtensions ,
29
+ ExtractStoreExtensions ,
29
30
UnknownIfNonSpecific ,
30
31
} from './tsHelpers'
31
32
import type { Tuple } from './utils'
32
- import type { GetDefaultEnhancers } from './getDefaultEnhancers'
33
- import { buildGetDefaultEnhancers } from './getDefaultEnhancers'
34
-
35
- const IS_PRODUCTION = process . env . NODE_ENV === 'production'
36
33
37
34
/**
38
35
* Options for `configureStore()`.
@@ -146,15 +143,22 @@ export function configureStore<
146
143
)
147
144
}
148
145
149
- if ( ! IS_PRODUCTION && middleware && typeof middleware !== 'function' ) {
146
+ if (
147
+ process . env . NODE_ENV !== 'production' &&
148
+ middleware &&
149
+ typeof middleware !== 'function'
150
+ ) {
150
151
throw new Error ( '`middleware` field must be a callback' )
151
152
}
152
153
153
154
let finalMiddleware : Tuple < Middlewares < S > >
154
155
if ( typeof middleware === 'function' ) {
155
156
finalMiddleware = middleware ( getDefaultMiddleware )
156
157
157
- if ( ! IS_PRODUCTION && ! Array . isArray ( finalMiddleware ) ) {
158
+ if (
159
+ process . env . NODE_ENV !== 'production' &&
160
+ ! Array . isArray ( finalMiddleware )
161
+ ) {
158
162
throw new Error (
159
163
'when using a middleware builder function, an array of middleware must be returned' ,
160
164
)
@@ -163,7 +167,7 @@ export function configureStore<
163
167
finalMiddleware = getDefaultMiddleware ( )
164
168
}
165
169
if (
166
- ! IS_PRODUCTION &&
170
+ process . env . NODE_ENV !== 'production' &&
167
171
finalMiddleware . some ( ( item : any ) => typeof item !== 'function' )
168
172
) {
169
173
throw new Error (
@@ -176,7 +180,7 @@ export function configureStore<
176
180
if ( devTools ) {
177
181
finalCompose = composeWithDevTools ( {
178
182
// Enable capture of stack traces for dispatched Redux actions
179
- trace : ! IS_PRODUCTION ,
183
+ trace : process . env . NODE_ENV !== 'production' ,
180
184
...( typeof devTools === 'object' && devTools ) ,
181
185
} )
182
186
}
@@ -185,7 +189,11 @@ export function configureStore<
185
189
186
190
const getDefaultEnhancers = buildGetDefaultEnhancers < M > ( middlewareEnhancer )
187
191
188
- if ( ! IS_PRODUCTION && enhancers && typeof enhancers !== 'function' ) {
192
+ if (
193
+ process . env . NODE_ENV !== 'production' &&
194
+ enhancers &&
195
+ typeof enhancers !== 'function'
196
+ ) {
189
197
throw new Error ( '`enhancers` field must be a callback' )
190
198
}
191
199
@@ -194,19 +202,19 @@ export function configureStore<
194
202
? enhancers ( getDefaultEnhancers )
195
203
: getDefaultEnhancers ( )
196
204
197
- if ( ! IS_PRODUCTION && ! Array . isArray ( storeEnhancers ) ) {
205
+ if ( process . env . NODE_ENV !== 'production' && ! Array . isArray ( storeEnhancers ) ) {
198
206
throw new Error ( '`enhancers` callback must return an array' )
199
207
}
200
208
if (
201
- ! IS_PRODUCTION &&
209
+ process . env . NODE_ENV !== 'production' &&
202
210
storeEnhancers . some ( ( item : any ) => typeof item !== 'function' )
203
211
) {
204
212
throw new Error (
205
213
'each enhancer provided to configureStore must be a function' ,
206
214
)
207
215
}
208
216
if (
209
- ! IS_PRODUCTION &&
217
+ process . env . NODE_ENV !== 'production' &&
210
218
finalMiddleware . length &&
211
219
! storeEnhancers . includes ( middlewareEnhancer )
212
220
) {
0 commit comments