Redux middleware that detects mutations between and outside redux dispatches. For development use only.
Installations
npm install redux-immutable-state-invariant
Developer
leoasis
Developer Guide
Module System
CommonJS
Min. Node Version
Typescript Support
No
Node Version
6.11.1
NPM Version
5.4.1
Statistics
937 Stars
64 Commits
37 Forks
6 Watching
2 Branches
13 Contributors
Updated on 21 Nov 2024
Languages
JavaScript (99.11%)
HTML (0.89%)
Total Downloads
Cumulative downloads
Total Downloads
28,239,692
Last day
5.6%
14,302
Compared to previous day
Last week
9.7%
75,628
Compared to previous week
Last month
12.9%
295,866
Compared to previous month
Last year
-8.7%
3,339,578
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
2
redux-immutable-state-invariant
Redux middleware that spits an error on you when you try to mutate your state either inside a dispatch or between dispatches. For development use only!
Why?
Because you're not allowed to mutate your state in your reducers! And by extension, you shouldn't mutate them either outside. In order to change state in your app, you should always return a new instance of your state with the changes.
If you're using a library such as Immutable.js
, this is automatically done for you since the structures provided by that library don't allow you to mutate them (as long as you don't have mutable stuff as values in those collections). However, if you're using regular objects and arrays, you should be careful to avoid mutations.
How to install
This lib is intended to use only during development. Don't use this in production!
1npm install --save-dev redux-immutable-state-invariant
How to use
As said above, don't use this in production! It involves a lot of object copying and will degrade your app's performance. This is intended to be a tool to aid you in development and help you catch bugs.
To use it, just add it as a middleware in your redux store:
1const {applyMiddleware, combineReducers, createStore} = require('redux'); 2const thunk = require('redux-thunk'); 3const reducer = require('./reducers/index'); 4 5// Be sure to ONLY add this middleware in development! 6const middleware = process.env.NODE_ENV !== 'production' ? 7 [require('redux-immutable-state-invariant').default(), thunk] : 8 [thunk]; 9 10// Note passing middleware as the last argument to createStore requires redux@>=3.1.0 11const store = createStore( 12 reducer, 13 applyMiddleware(...middleware) 14);
Then if you're doing things correctly, you should see nothing different. But if you don't, that is, if you're mutating your data somewhere in your app either in a dispatch or between dispatches, an error will be thrown with a (hopefully) descriptive message.
API
immutableStateInvariantMiddleware({ isImmutable, ignore })
The default export is a factory to create the middleware. Supports an options
argument (optional) to customize middleware behavior. It returns the middleware
function when called. The following properties are supported in options
:
Options
-
isImmutable
function(value)
- Specify if a value should be treated as immutable or not. The default implementation will returntrue
for primitive types (like numbers, strings, booleans,null
andundefined
). Useful if some state of your app uses a library likeImmutable.js
and you want to let the middleware know that the data structures are indeed immutable. -
ignore
string[]
- specify branch(es) of the state object to ignore when detecting for mutations. The elements of the array should be dot-separated "path" strings that match named nodes from the root state.1// example: ignore mutation detection along the 'foo' & 'bar.thingsToIgnore' branches 2const middleware = immutableStateInvariantMiddleware({ 3 ignore: [ 4 'foo', 5 'bar.thingsToIgnore' 6 ] 7});
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE.md:0
- Info: FSF or OSI recognized license: MIT License: LICENSE.md:0
Reason
0 existing vulnerabilities detected
Reason
Found 7/13 approved changesets -- score normalized to 5
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 24 are checked with a SAST tool
Score
3.7
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to redux-immutable-state-invariant
@types/redux-immutable-state-invariant
TypeScript definitions for redux-immutable-state-invariant
redux-immutable
redux-immutable is used to create an equivalent function of Redux combineReducers that works with Immutable.js state.
reselect
Selectors for Redux.
tiny-invariant
A tiny invariant function