Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jakelazaroff/redux-localstorage-immutable
Enhancer for redux-localstorage that allows you to persist an immutable store
https://github.com/jakelazaroff/redux-localstorage-immutable
Last synced: about 2 months ago
JSON representation
Enhancer for redux-localstorage that allows you to persist an immutable store
- Host: GitHub
- URL: https://github.com/jakelazaroff/redux-localstorage-immutable
- Owner: jakelazaroff
- License: mit
- Created: 2015-12-04T04:37:29.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2020-03-15T17:02:17.000Z (almost 5 years ago)
- Last Synced: 2024-08-22T18:41:00.015Z (4 months ago)
- Language: JavaScript
- Homepage:
- Size: 9.77 KB
- Stars: 8
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# redux-localstorage-immutable
[![npm](https://img.shields.io/npm/v/redux-localstorage-immutable.svg?style=flat-square)]([![npm](https://img.shields.io/npm/dm/redux-localstorage-immutable.svg?style=flat-square)](https://www.npmjs.com/package/redux-localstorage-immutable)) [![npm](https://img.shields.io/npm/dm/redux-localstorage-immutable.svg?style=flat-square)](https://www.npmjs.com/package/redux-localstorage-immutable)
Enhancer for redux-localstorage that allows you to persist an immutable store.
## Installation
```
npm install --save redux-localstorage-immutable
```## Usage
```javascript
import { serialize, deserialize } from 'redux-localstorage-immutable';const reducers = compose(
mergePersistedState(deserialize)
)(reducers);const storage = compose(
serialize
)(adapter(window.localStorage));
```## Methods
**Note:** I've documented the parameters here to explain what each method does, but in practice you can just pass them to the appropriate methods without worrying about it.
### deserialize (state, payload)
Merges `payload` into `state` and returns the resulting Immutable. Used to take the JSON string from local storage and merge it into the store.
### serialize (storage)
Adds a `put` that converts the state to a JavaScript object and passes the storage object along. Used to prepare your Immutable for local storage. Probably should go before any other enhancers, unless they don't care about the state (like [redux-localstorage-debounce](https://github.com/elgerlambert/redux-localstorage-debounce)) or they're expecting an Immutable rather than a plain JavaScript object.
## Thanks
Cheers to [redux-localstorage](https://github.com/elgerlambert/redux-localstorage) and [redux-immutablejs](https://github.com/indexiatech/redux-immutablejs)!