-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Feature/immutable invariant #381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 10 commits
762f161
63130ca
4296e74
717658b
69758eb
b7daaab
d2ede76
076d896
1c863c2
3a9e5a7
603612d
55842ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,56 @@ Redux Toolkit exports some of its internal utilities, and re-exports additional | |
|
||
## Internal Exports | ||
|
||
### `createImmutalStateInvariantMiddleware` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before we release 1.3 we should probably extract these into their own docs page or something, but good enough for now There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, typo here: |
||
|
||
Creates an instance of the `immutable-state-invariant` middleware described in [`getDefaultMiddleware`](./getDefaultMiddleware.md). | ||
|
||
Accepts a single configuration object parameter, with the following options: | ||
|
||
```ts | ||
function createImmutableStateInvariantMiddleware({ | ||
// The function to check if a value is considered to be immutable. | ||
// This function is applied recursively to every value contained in the state. | ||
// The default implementation will return true for primitive types (like numbers, strings, booleans, null and undefined). | ||
isImmutable?: (value: any) => boolean | ||
// An array of dot-separated path strings that match named nodes from the root state to ignore when checking for immutability. | ||
// Defaults to undefined | ||
ignoredPaths?: string[] | ||
}) | ||
``` | ||
|
||
Example: | ||
|
||
```js | ||
import { | ||
createSlice, | ||
configureStore, | ||
createImmutableStateInvariantMiddleware | ||
} from '@reduxjs/toolkit' | ||
|
||
const exampleSlice = createSlice({ | ||
name: 'example', | ||
initialState: { | ||
user: 'will track changes', | ||
ignoredPath: 'single level', | ||
ignoredNested: { | ||
one: 'one', | ||
two: 'two' | ||
} | ||
}, | ||
reducers: {} | ||
}) | ||
|
||
const immutableInvariantMiddleware = createImmutableStateInvariantMiddleware({ | ||
ignoredPaths: ['ignoredPath', 'ignoredNested.one', 'ignoredNested.two'] | ||
}) | ||
|
||
const store = configureStore({ | ||
reducer: exampleSlice.reducer, | ||
middleware: [immutableInvariantMiddleware] | ||
}) | ||
``` | ||
|
||
### `createSerializableStateInvariantMiddleware` | ||
|
||
Creates an instance of the `serializable-state-invariant` middleware described in [`getDefaultMiddleware`](./getDefaultMiddleware.md). | ||
|
Uh oh!
There was an error while loading. Please reload this page.