new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Redux Toolkit · API · all subjects

immutabilitymiddleware

7 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Immutability Middleware overview

The Immutability Middleware is a port of the redux-immutable-state-invariant middleware, customized for Redux Toolkit. It detects mutations and throws them as errors. This middleware is added to the store by default by configureStore and getDefaultMiddleware.

ImmutableStateInvariantMiddlewareOptions interface

The ImmutableStateInvariantMiddlewareOptions interface has three optional properties: isImmutable (a callback function IsImmutableFunc that checks if a value is immutable, applied recursively to every value in state, returns true for primitives like numbers, strings, booleans, null and undefined by default), ignoredPaths (an array of dot-separated path strings or RegExps that match named nodes from root state to ignore when checking for immutability, defaults to undefined), and warnAfter (prints a warning if checks take longer than N milliseconds, default is 32ms).

createImmutableStateInvariantMiddleware function

createImmutableStateInvariantMiddleware creates an instance of the immutability check middleware with the given ImmutableStateInvariantMiddlewareOptions. It takes options as a parameter and returns middleware that can be used in configureStore. Most users will not need to call this directly as getDefaultMiddleware already does so.

isImmutableDefault export

isImmutableDefault is the default implementation of the immutability check. It returns true for primitive types (numbers, strings, booleans, null, and undefined). The implementation is: return (typeof value !== 'object' || value === null || typeof value === 'undefined')

createImmutableStateInvariantMiddleware usage with getDefaultMiddleware

When customizing immutability middleware behavior without removing other default middleware, pass an immutableCheck configuration object to getDefaultMiddleware. For example: middleware: (getDefaultMiddleware) => getDefaultMiddleware({ immutableCheck: { ignoredPaths: ['ignoredPath', 'ignoredNested.one'] } }). This replaces the original default middleware with customized versions.

createImmutableStateInvariantMiddleware function

createImmutableStateInvariantMiddleware(options?: ImmutableStateInvariantMiddlewareOptions): Middleware. Returns middleware that checks for immutability violations.

ImmutableStateInvariantMiddlewareOptions interface

ImmutableStateInvariantMiddlewareOptions has properties: ignore (optional, string[]), ignoredPaths (optional, string[]), isImmutable (optional, IsImmutableFunc), warnAfter (optional, number).

Give your agent this brain