redux-localstorage
redux-localstorage copied to clipboard
Add an example config for Immutable.js to the README.md
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)
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.
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
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 Can you create a PR to the 1.0 branch with your example?
@NameFILIP done!
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