Skip to content

Commit 23bb427

Browse files
committed
Update docs, add test, alias ignore->ignoredPaths
1 parent 261ff26 commit 23bb427

4 files changed

+26
-4
lines changed

docs/api/getDefaultMiddleware.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ interface ThunkOptions<E = any> {
110110

111111
interface ImmutableStateInvariantMiddlewareOptions {
112112
isImmutable?: (value: any) => boolean
113-
ignore?: string[]
113+
ignoredPaths?: string[]
114+
warnAfter?: number
114115
}
115116

116117
interface SerializableStateInvariantMiddlewareOptions {

etc/redux-toolkit.api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,8 @@ export type IdSelector<T> = (model: T) => EntityId;
277277

278278
// @public
279279
export interface ImmutableStateInvariantMiddlewareOptions {
280+
// (undocumented)
281+
ignore?: string[];
280282
// (undocumented)
281283
ignoredPaths?: string[];
282284
// (undocumented)

src/immutableStateInvariantMiddleware.test.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ describe('createImmutableStateInvariantMiddleware', () => {
110110
}).not.toThrow()
111111
})
112112

113-
it('respects "ignore" option', () => {
113+
it('respects "ignoredPaths" option', () => {
114114
const next: Dispatch = action => {
115115
state.foo.bar.push(5)
116116
return action
@@ -123,6 +123,19 @@ describe('createImmutableStateInvariantMiddleware', () => {
123123
}).not.toThrow()
124124
})
125125

126+
it('alias "ignore" to "ignoredPath" and respects option', () => {
127+
const next: Dispatch = action => {
128+
state.foo.bar.push(5)
129+
return action
130+
}
131+
132+
const dispatch = middleware({ ignore: ['foo.bar'] })(next)
133+
134+
expect(() => {
135+
dispatch({ type: 'SOME_ACTION' })
136+
}).not.toThrow()
137+
})
138+
126139
it('Should print a warning if execution takes too long', () => {
127140
state.foo.bar = new Array(10000).fill({ value: 'more' })
128141

src/immutableStateInvariantMiddleware.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ export interface ImmutableStateInvariantMiddlewareOptions {
187187
isImmutable?: IsImmutableFunc
188188
ignoredPaths?: string[]
189189
warnAfter?: number
190+
ignore?: string[] // @deprecated. Use ignoredPaths
190191
}
191192

192193
/**
@@ -205,11 +206,16 @@ export function createImmutableStateInvariantMiddleware(
205206
return () => next => action => next(action)
206207
}
207208

208-
const {
209+
let {
209210
isImmutable = isImmutableDefault,
210211
ignoredPaths,
211-
warnAfter = 32
212+
warnAfter = 32,
213+
ignore
212214
} = options
215+
216+
// Alias ignore->ignoredPaths, but prefer ignoredPaths if present
217+
ignoredPaths = ignoredPaths || ignore
218+
213219
const track = trackForMutations.bind(null, isImmutable, ignoredPaths)
214220

215221
return ({ getState }) => {

0 commit comments

Comments
 (0)