@@ -3,28 +3,6 @@ import { getTimeMeasureUtils } from './utils'
3
3
4
4
type EntryProcessor = ( key : string , value : any ) => any
5
5
6
- const isProduction : boolean = process . env . NODE_ENV === 'production'
7
- const prefix : string = 'Invariant failed'
8
-
9
- // Throw an error if the condition fails
10
- // Strip out error messages for production
11
- // > Not providing an inline default argument for message as the result is smaller
12
- function invariant ( condition : any , message ?: string ) {
13
- if ( condition ) {
14
- return
15
- }
16
- // Condition not passed
17
-
18
- // In production we strip the message but still throw
19
- if ( isProduction ) {
20
- throw new Error ( prefix )
21
- }
22
-
23
- // When not in production we allow the message to pass through
24
- // *This block will be removed in production builds*
25
- throw new Error ( `${ prefix } : ${ message || '' } ` )
26
- }
27
-
28
6
/**
29
7
* The default `isImmutable` function.
30
8
*
@@ -62,7 +40,7 @@ function trackProperties(
62
40
const tracked : Partial < TrackedProperty > = { value : obj }
63
41
64
42
if ( ! isImmutable ( obj ) && ! checkedObjects . has ( obj ) ) {
65
- checkedObjects . add ( obj ) ;
43
+ checkedObjects . add ( obj )
66
44
tracked . children = { }
67
45
68
46
for ( const key in obj ) {
@@ -248,12 +226,13 @@ export function createImmutableStateInvariantMiddleware(
248
226
// Track before potentially not meeting the invariant
249
227
tracker = track ( state )
250
228
251
- invariant (
252
- ! result . wasMutated ,
253
- `A state mutation was detected between dispatches, in the path '${
254
- result . path || ''
255
- } '. This may cause incorrect behavior. (https://redux.js.org/style-guide/style-guide#do-not-mutate-state)`
256
- )
229
+ if ( result . wasMutated ) {
230
+ throw new Error (
231
+ `A state mutation was detected between dispatches, in the path '${
232
+ result . path || ''
233
+ } '. This may cause incorrect behavior. (https://redux.js.org/style-guide/style-guide#do-not-mutate-state)`
234
+ )
235
+ }
257
236
} )
258
237
259
238
const dispatchedAction = next ( action )
@@ -265,15 +244,15 @@ export function createImmutableStateInvariantMiddleware(
265
244
// Track before potentially not meeting the invariant
266
245
tracker = track ( state )
267
246
268
- result . wasMutated &&
269
- invariant (
270
- ! result . wasMutated ,
247
+ if ( result . wasMutated ) {
248
+ throw new Error (
271
249
`A state mutation was detected inside a dispatch, in the path: ${
272
250
result . path || ''
273
251
} . Take a look at the reducer(s) handling the action ${ stringify (
274
252
action
275
253
) } . (https://redux.js.org/style-guide/style-guide#do-not-mutate-state)`
276
254
)
255
+ }
277
256
} )
278
257
279
258
measureUtils . warnIfExceeded ( )
0 commit comments