Skip to content

Commit 6db0c61

Browse files
committed
Remove unnecessary IS_PRODUCTION variable
1 parent 73ac0b0 commit 6db0c61

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

packages/toolkit/src/configureStore.ts

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,35 @@
11
import type {
2+
Action,
3+
Middleware,
24
Reducer,
35
ReducersMapObject,
4-
Middleware,
5-
Action,
6-
StoreEnhancer,
76
Store,
7+
StoreEnhancer,
88
UnknownAction,
99
} from 'redux'
1010
import {
1111
applyMiddleware,
12-
createStore,
13-
compose,
1412
combineReducers,
13+
compose,
14+
createStore,
1515
isPlainObject,
1616
} from 'redux'
1717
import type { DevToolsEnhancerOptions as DevToolsOptions } from './devtoolsExtension'
1818
import { composeWithDevTools } from './devtoolsExtension'
19-
19+
import type { GetDefaultEnhancers } from './getDefaultEnhancers'
20+
import { buildGetDefaultEnhancers } from './getDefaultEnhancers'
2021
import type {
21-
ThunkMiddlewareFor,
2222
GetDefaultMiddleware,
23+
ThunkMiddlewareFor,
2324
} from './getDefaultMiddleware'
2425
import { buildGetDefaultMiddleware } from './getDefaultMiddleware'
2526
import type {
2627
ExtractDispatchExtensions,
27-
ExtractStoreExtensions,
2828
ExtractStateExtensions,
29+
ExtractStoreExtensions,
2930
UnknownIfNonSpecific,
3031
} from './tsHelpers'
3132
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'
3633

3734
/**
3835
* Options for `configureStore()`.
@@ -146,15 +143,22 @@ export function configureStore<
146143
)
147144
}
148145

149-
if (!IS_PRODUCTION && middleware && typeof middleware !== 'function') {
146+
if (
147+
process.env.NODE_ENV !== 'production' &&
148+
middleware &&
149+
typeof middleware !== 'function'
150+
) {
150151
throw new Error('`middleware` field must be a callback')
151152
}
152153

153154
let finalMiddleware: Tuple<Middlewares<S>>
154155
if (typeof middleware === 'function') {
155156
finalMiddleware = middleware(getDefaultMiddleware)
156157

157-
if (!IS_PRODUCTION && !Array.isArray(finalMiddleware)) {
158+
if (
159+
process.env.NODE_ENV !== 'production' &&
160+
!Array.isArray(finalMiddleware)
161+
) {
158162
throw new Error(
159163
'when using a middleware builder function, an array of middleware must be returned',
160164
)
@@ -163,7 +167,7 @@ export function configureStore<
163167
finalMiddleware = getDefaultMiddleware()
164168
}
165169
if (
166-
!IS_PRODUCTION &&
170+
process.env.NODE_ENV !== 'production' &&
167171
finalMiddleware.some((item: any) => typeof item !== 'function')
168172
) {
169173
throw new Error(
@@ -176,7 +180,7 @@ export function configureStore<
176180
if (devTools) {
177181
finalCompose = composeWithDevTools({
178182
// Enable capture of stack traces for dispatched Redux actions
179-
trace: !IS_PRODUCTION,
183+
trace: process.env.NODE_ENV !== 'production',
180184
...(typeof devTools === 'object' && devTools),
181185
})
182186
}
@@ -185,7 +189,11 @@ export function configureStore<
185189

186190
const getDefaultEnhancers = buildGetDefaultEnhancers<M>(middlewareEnhancer)
187191

188-
if (!IS_PRODUCTION && enhancers && typeof enhancers !== 'function') {
192+
if (
193+
process.env.NODE_ENV !== 'production' &&
194+
enhancers &&
195+
typeof enhancers !== 'function'
196+
) {
189197
throw new Error('`enhancers` field must be a callback')
190198
}
191199

@@ -194,19 +202,19 @@ export function configureStore<
194202
? enhancers(getDefaultEnhancers)
195203
: getDefaultEnhancers()
196204

197-
if (!IS_PRODUCTION && !Array.isArray(storeEnhancers)) {
205+
if (process.env.NODE_ENV !== 'production' && !Array.isArray(storeEnhancers)) {
198206
throw new Error('`enhancers` callback must return an array')
199207
}
200208
if (
201-
!IS_PRODUCTION &&
209+
process.env.NODE_ENV !== 'production' &&
202210
storeEnhancers.some((item: any) => typeof item !== 'function')
203211
) {
204212
throw new Error(
205213
'each enhancer provided to configureStore must be a function',
206214
)
207215
}
208216
if (
209-
!IS_PRODUCTION &&
217+
process.env.NODE_ENV !== 'production' &&
210218
finalMiddleware.length &&
211219
!storeEnhancers.includes(middlewareEnhancer)
212220
) {

0 commit comments

Comments
 (0)