
Research
/Security News
Contagious Interview Campaign Escalates With 67 Malicious npm Packages and New Malware Loader
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.
redux-sessionstorage
Advanced tools
Store enhancer that syncs (a subset of) your redux store state to sessionstorage.
The same library by Elger Lambert, but for sessionStorage instead of localStorage.
Store enhancer that syncs (a subset) of your Redux store state to sessionstorage.
NOTE: Be sure to check out the 1.0-breaking-changes branch (available on npm as redux-sessionstorage@rc
). It includes support for flexible storage backends, including (but not limited to) sessionStorage
and react-natives' AsyncStorage
.
npm install --save redux-sessionstorage
import {compose, createStore} from 'redux';
import persistState from 'redux-sessionstorage'
const createPersistentStore = compose(
persistState(/*paths, config*/)
)(createStore)
const store = createPersistentStore(/*reducer, initialState*/)
type paths = Void | String | Array<String>
If left Void
, persistState will sync Redux's complete store state with sessionStorage. Alternatively you may specify which part(s) of your state should be persisted.
Note: Currently no support for nested paths. Only "top-level" paths are supported, i.e. state[path]. If your needs are more complex and you require more control over which parts of your store's state should be persisted you can define your own strategy through config.slicer
type config.key = String
The sessionStorage key used to store state. The default value is redux
.
type config.slicer = (paths: Any) => (state: Collection) => subset: Collection
Config.slicer allows you to define your own function which will be used to determine which parts should be synced with sessionStorage. It should look something like this:
function myCustomSlicer (paths) {
return (state) => {
let subset = {}
/*Custom logic goes here*/
return subset
}
}
It is called with the paths argument supplied to persistState. It should return a function that will be called with the store's state, which should return a subset that matches the original shape/structure of the store - it's this subset that'll be persisted.
If, for example, you want to dynamically persist parts of your store state based on a user's preference, defining your own slicer
allows you to do that. Simply add something along the following lines to your customSlicer function:
paths.forEach((path) => {
if (state[path].persistToSessionStorage)
subset[path] = state[path]
}
If you're using immutable collections or some other custom collection, redux-sessionstorage exposes a number of functions that can be overridden by providing the following config options. These allow you to specify your own tranformations based on your needs. If your using ordinary javascript Objects, Arrays or primitives, you shouldn't have to concern yourself with these options.
type config.serialize = (subset: Collection) => serializedData: String
The default serialization strategy is JSON.stringify. Specifying a serialize function as part of your config will override this. This function receives a single argument (the subset of your store's state about to be persisted) and should return a serialized (i.e. stringified) representation thereof.
type config.deserialize = (serializedData: String) => subset: Collection
The default deserialization strategy is JSON.parse. Specifying a deserialize function as part of your config will override this. This function receives a single argument (a serialized representation of your persisted state) and should return the data in a format that's expected by your application.
type config.merge = (initialState: Collection, persistedState: Collection) => finalInitialState: Collection
During initialization any persisted state is merged with the initialState passed in as an argument to createStore
.
The default strategy extends
the initialState with the persistedState. Override this function if that doesn't work for you. Note: this is only required if you want to merge values within an immutable collection. If your values are immutable, but the object that holds them is not, the default strategy should work just fine.
FAQs
Store enhancer that syncs (a subset of) your redux store state to sessionstorage.
The npm package redux-sessionstorage receives a total of 605 weekly downloads. As such, redux-sessionstorage popularity was classified as not popular.
We found that redux-sessionstorage demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.