Skip to content

Commit e3c2cf0

Browse files
authored
Export createImmutableStateInvariantMiddleware, fix typo (#449)
* Export createImmutableStateInvariantMiddleware, fix typo * Add @public tag to new exports
1 parent 5730632 commit e3c2cf0

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-3
lines changed

etc/redux-toolkit.api.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ export function createEntityAdapter<T>(options?: {
136136
sortComparer?: false | Comparer<T>;
137137
}): EntityAdapter<T>;
138138

139+
// @public
140+
export function createImmutableStateInvariantMiddleware(options?: ImmutableStateInvariantMiddlewareOptions): Middleware;
141+
139142
export { createNextState }
140143

141144
// @public
@@ -213,6 +216,19 @@ export function getType<T extends string>(actionCreator: PayloadActionCreator<an
213216
// @alpha (undocumented)
214217
export type IdSelector<T> = (model: T) => EntityId;
215218

219+
// @public
220+
export interface ImmutableStateInvariantMiddlewareOptions {
221+
// (undocumented)
222+
ignoredPaths?: string[];
223+
// (undocumented)
224+
isImmutable?: IsImmutableFunc;
225+
// (undocumented)
226+
warnAfter?: number;
227+
}
228+
229+
// @public
230+
export function isImmutableDefault(value: unknown): boolean;
231+
216232
// @public
217233
export function isPlain(val: any): boolean;
218234

src/immutableStateInvariantMiddleware.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ function getSerialize(
6161
}
6262
}
6363

64+
/**
65+
* The default `isImmutable` function.
66+
*
67+
* @public
68+
*/
6469
export function isImmutableDefault(value: unknown): boolean {
6570
return (
6671
typeof value !== 'object' || value === null || typeof value === 'undefined'
@@ -69,13 +74,13 @@ export function isImmutableDefault(value: unknown): boolean {
6974

7075
export function trackForMutations(
7176
isImmutable: IsImmutableFunc,
72-
ingorePaths: string[] | undefined,
77+
ignorePaths: string[] | undefined,
7378
obj: any
7479
) {
75-
const trackedProperties = trackProperties(isImmutable, ingorePaths, obj)
80+
const trackedProperties = trackProperties(isImmutable, ignorePaths, obj)
7681
return {
7782
detectMutations() {
78-
return detectMutations(isImmutable, ingorePaths, trackedProperties, obj)
83+
return detectMutations(isImmutable, ignorePaths, trackedProperties, obj)
7984
}
8085
}
8186
}
@@ -172,12 +177,27 @@ function detectMutations(
172177
}
173178

174179
type IsImmutableFunc = (value: any) => boolean
180+
181+
/**
182+
* Options for `createImmutableStateInvariantMiddleware()`.
183+
*
184+
* @public
185+
*/
175186
export interface ImmutableStateInvariantMiddlewareOptions {
176187
isImmutable?: IsImmutableFunc
177188
ignoredPaths?: string[]
178189
warnAfter?: number
179190
}
180191

192+
/**
193+
* Creates a middleware that checks whether any state was mutated in between
194+
* dispatches or during a dispatch. If any mutations are detected, an error is
195+
* thrown.
196+
*
197+
* @param options Middleware options.
198+
*
199+
* @public
200+
*/
181201
export function createImmutableStateInvariantMiddleware(
182202
options: ImmutableStateInvariantMiddlewareOptions = {}
183203
): Middleware {

src/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ export {
5858
CaseReducerWithPrepare,
5959
SliceActionCreator
6060
} from './createSlice'
61+
export {
62+
// js
63+
createImmutableStateInvariantMiddleware,
64+
isImmutableDefault,
65+
// types
66+
ImmutableStateInvariantMiddlewareOptions
67+
} from './immutableStateInvariantMiddleware'
6168
export {
6269
// js
6370
createSerializableStateInvariantMiddleware,

0 commit comments

Comments
 (0)