Skip to content

Commit a680049

Browse files
committed
Conditionally import immutable-state-invariant middleware
1 parent b38b2f7 commit a680049

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

src/configureStore.test.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,20 @@ import * as devtools from 'redux-devtools-extension'
55
import thunk from 'redux-thunk'
66

77
describe('getDefaultMiddleware', () => {
8+
const ORIGINAL_NODE_ENV = process.env.NODE_ENV
9+
10+
afterEach(() => {
11+
process.env.NODE_ENV = ORIGINAL_NODE_ENV
12+
})
13+
814
it('returns an array with only redux-thunk in production', () => {
9-
expect(getDefaultMiddleware(true)).toEqual([thunk])
15+
process.env.NODE_ENV = "production";
16+
17+
expect(getDefaultMiddleware()).toEqual([thunk])
1018
})
1119

1220
it('returns an array with additional middleware in development', () => {
13-
const middleware = getDefaultMiddleware(false)
21+
const middleware = getDefaultMiddleware()
1422
expect(middleware).toContain(thunk)
1523
expect(middleware.length).toBeGreaterThan(1)
1624
})

src/configureStore.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
} from 'redux'
1616
import { composeWithDevTools } from 'redux-devtools-extension'
1717
import thunk, { ThunkDispatch, ThunkMiddleware } from 'redux-thunk'
18-
import createImmutableStateInvariantMiddleware from 'redux-immutable-state-invariant'
1918
import createSerializableStateInvariantMiddleware from './serializableStateInvariantMiddleware'
2019

2120
import isPlainObject from './isPlainObject'
@@ -29,12 +28,15 @@ const IS_PRODUCTION = process.env.NODE_ENV === 'production'
2928
*
3029
* @return The default middleware used by `configureStore()`.
3130
*/
32-
export function getDefaultMiddleware<S = any, A extends Action = AnyAction>(
33-
isProduction = IS_PRODUCTION
34-
): [ThunkMiddleware<S, A>, ...Middleware<{}, S>[]] {
31+
export function getDefaultMiddleware<S = any, A extends Action = AnyAction>(): [
32+
ThunkMiddleware<S, A>,
33+
...Middleware<{}, S>[]
34+
] {
3535
let middlewareArray: [ThunkMiddleware<S, A>, ...Middleware<{}, S>[]] = [thunk]
3636

37-
if (!isProduction) {
37+
if (process.env.NODE_ENV !== 'production') {
38+
const createImmutableStateInvariantMiddleware = require('redux-immutable-state-invariant').default
39+
3840
middlewareArray = [
3941
createImmutableStateInvariantMiddleware(),
4042
thunk,

0 commit comments

Comments
 (0)