Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
redux-localstorage
Advanced tools
Store enhancer that accepts any (enhanced!) storage backend to persist store state changes.
Store enhancer that accepts any (enhanced!) storage backend to persist store state changes.
Redux-localstorage provides adapters for localStorage
, sessionStorage
and AsyncStorage
as well as storage enhancers such as filter
so that you can get going with minimal effort. You can then create your own storage enhancers to meet any other (application specific) needs!
npm install --save redux-localstorage
import {compose, createStore} from 'redux';
import adapter from 'redux-localstorage/lib/adapters/localStorage';
import {filter} from 'redux-localstorage/lib/enhancers';
import persistState from 'redux-localstorage';
const storage = compose(
filter('nested.key'),
adapter(window.localStorage)
);
const createPersistentStore = compose(
persistState(storage, 'my-storage-key'),
createStore
);
const store = createPersistentStore(/*reducer, initialState*/);
type storage = Storage (Object)
An object that provides (enhanced) methods for data persistence, retrieval and removal as put, get & del. Defaults to adapter(localStorage).
type key = String
The key used to store (and retrieve) persisted state. Defaults to 'redux-localstorage'.
Redux-localstorage can be made to work with any storage implementation - it doesn't even have to be local! All that is required is that the storage that is passed in exposes the following methods.
storage = {
put: function(key, value, callback) {},
get: function(key, callback) {},
del: function(key, callback) {}
};
A number of adapters are provided to wrap existing storage API's so that they conform to these requirements. But you could create your own storage object and point these methods to any endpoint you like!
Redux-localstorage currently provides adapters for localStorage
, sessionStorage
and AsyncStorage
. An adapter creates a thin wrapper that transforms a storage API so that it conforms to the stated requirements. The original storage object passed to an adapter can be accessed through adapted[0]
; this provides you access to all the original storage methods when creating a storage enhancer.
import {compose, createStore} from 'redux';
import {AsyncStorage} from 'react-native';
import adapter from 'redux-localstorage/lib/adapters/AsyncStorage';
import persistState from 'redux-localstorage';
const storage = adapter(AsyncStorage)
// storage[0] === AsyncStorage
const createPersistentStore = compose(
persistState(storage, 'my-storage-key'),
createStore
);
type enhancer = (Storage) => Storage
Through functional composition it's really easy to enhance a storage object. This provides a lot of flexibility, allowing for fun stuff like:
const storage = compose(
debounce(1000),
filter(['key', 'another.key']),
serialization,
errorHandling,
adapter(window.localStorage)
);
const createPersistentStore = compose(
persistState(storage, 'my-storage-key'),
createStore
);
Check out the available enhancers and recipes to get going and create your own enhancers!
MIT
FAQs
Store enhancer that syncs (a subset of) your redux store state to localstorage.
We found that redux-localstorage 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.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.