Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mathieudutour/redux-storage-engine-localstorage-map
https://github.com/mathieudutour/redux-storage-engine-localstorage-map
Last synced: 9 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/mathieudutour/redux-storage-engine-localstorage-map
- Owner: mathieudutour
- License: mit
- Created: 2016-09-07T14:57:36.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2016-09-07T14:58:20.000Z (about 8 years ago)
- Last Synced: 2024-10-17T16:13:42.294Z (26 days ago)
- Language: JavaScript
- Size: 2.93 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# redux-storage-engine-localstorage-map
[![build](https://travis-ci.org/mathieudutour/redux-storage-engine-localstorage-map.svg)](https://travis-ci.org/mathieudutour/redux-storage-engine-localstorage-map)
`window.localStorage` based engine for [redux-storage][].
## Installation
npm install --save redux-storage-engine-localstorage-map
## Usage
Stores a subset of your state tree inside `window.localStorage`.
```js
import createEngine from 'redux-storage-engine-localstorage-map';
const engine = createEngine({
'my-save-key': ['reducer1', 'reducer2']
'my-second-save-key': ['reducer3', 'reducer4']
});
```You can customize the saving and loading process by providing a [`replacer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_replacer_parameter) and/or a [`reviver`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#Using_the_reviver_parameter).
```js
import createEngine from 'redux-storage-engine-localstorage-map';function replacer (key, value) {
if (typeof value === 'string') {
return 'foo';
}
return value;
}function reviver (key, value) {
if (key === 'foo') {
return 'bar';
}
return value;
});const engine = createEngine({
'my-save-key': ['reducer1', 'reducer2']
'my-second-save-key': ['reducer3', 'reducer4']
}, replacer, reviver);
```**Warning**: `localStorage` does not expose a async API and every save/load
operation will block the JS thread!## License
MIT
[redux-storage]: https://github.com/michaelcontento/redux-storage