redux-localstorage icon indicating copy to clipboard operation
redux-localstorage copied to clipboard

Add an example config for Immutable.js to the README.md

Open NameFILIP opened this issue 8 years ago • 6 comments

I've spent a couple of hours figuring out how to make it play well with Immutable.js Immutable.js is a quite popular library that's often used together with redux. It would be nice if the documentation contain an example of configuration (can be taken from here: https://github.com/elgerlambert/redux-localstorage/issues/22)

NameFILIP avatar Jun 17 '16 23:06 NameFILIP

Hi @NameFILIP,

There are a couple of comments in that issue with solutions, could you specify which comment in particular was helpful to you? Also, which version of redux-localstorage are you using?

In case you're using 1.0.0-x, did you also see #28 / https://github.com/jakelazaroff/redux-localstorage-immutable.

elgerlambert avatar Jun 20 '16 20:06 elgerlambert

The last one, from @kretz (https://github.com/elgerlambert/redux-localstorage/issues/22#issuecomment-158659363). It works fine with v0.4.1

I've looked at the 1.0.0-x version, but I currently just need the simplest solution

NameFILIP avatar Jun 20 '16 21:06 NameFILIP

The following should work using redux-localstorage 1.0.0 and redux-localstorage-immutable:

import {compose, createStore} from 'redux';
import rootReducer from './reducers';

import persistState, {mergePersistedState} from 'redux-localstorage';
import adapter from 'redux-localstorage/lib/adapters/localStorage';
import filter from 'redux-localstorage-filter';

import { serialize, deserialize } from 'redux-localstorage-immutable';

const reducer = compose(
  // apply deserialize from redux-localstorage-immutable
  mergePersistedState(deserialize)
)(rootReducer);

const storage = compose(
  // apply serialize from redux-localstorage-immutable
  serialize,
  filter('nested.key')
)(adapter(window.localStorage));

const enhancer = compose(
  /* applyMiddleware(...middlewares) */
  persistState(storage, 'my-storage-key')
);

const store = createStore(reducer /*, [initialState]*/, enhancer);

josephearl avatar Oct 04 '16 13:10 josephearl

@JosephEarl Can you create a PR to the 1.0 branch with your example?

NameFILIP avatar Oct 12 '16 21:10 NameFILIP

@NameFILIP done!

josephearl avatar Oct 13 '16 14:10 josephearl

i also got hung up on combineReducers which i had been importing from the base redux module - replacing with combineReducers from 'redux-immutable' fixed my serialization/deserialization exceptions: https://github.com/gajus/redux-immutable

steveinatorx avatar Dec 22 '16 19:12 steveinatorx