redux-persist-transform-immutable
redux-persist-transform-immutable copied to clipboard
Record rehydrating as a map
Hey having trouble to get my immutable records to rehydrate as a Record. Here is my code.
import {AsyncStorage} from 'react-native';
import createSagaMiddleware from 'redux-saga';
import devTools from 'remote-redux-devtools';
import {createStore, applyMiddleware, compose} from 'redux';
import thunk from 'redux-thunk';
import {persistStore, autoRehydrate} from 'redux-persist';
import reducer from './reducers';
import promise from './promise';
import rootSaga from 'Sagas';
import immutableTransform from 'redux-persist-transform-immutable'
import { Record } from 'immutable';
const sagaMiddleware = createSagaMiddleware()
const logger = store => next => action => {
console.log('dispatching', action)
let result = next(action)
console.log('next state', store.getState())
return result
}
const settings = Record({
timeZoneAuto: false,
tzName: '',
defaultDisplay: '',
}, 'settings');
export default configureStore = (onCompletion) => {
const enhancer = compose(applyMiddleware(promise, sagaMiddleware, logger), devTools({name: 'Supervisor', realtime: true}));
const store = createStore(reducer, enhancer, autoRehydrate({log: true}));
persistStore(
store,
{
storage: AsyncStorage,
transforms: [immutableTransform({records: [settings]})]
},
onCompletion
);
store.runSaga = sagaMiddleware.run(rootSaga);
return store;
}
Any ideas?
code superficially looks correct. I apologize I am not sure beyond that and as I am not currently using immutable it is hard for me to take a look. If you figure the issue out please report back!
We have a similar issue where our Immutable.List is coming back as a Immutable.Map using [email protected] and [email protected]. This may be upstream and related to this issue. We were able to solve this for now by rolling back to [email protected] and to [email protected]. This also only seems to happen when using AsyncStorage with react-native.
@rynbyjn I just noticed this was happening for me too. Thanks for the tip!
that is unfortunate. @rynbyjn what do you recommend for solving this at the lib level?
seems this might best be solved by making immutablejs a peer dep..
It's early days, but for the moment I was able to resolve this in our apps by requiring react-redux >= 5.0.4.
React-redux 5.0.4 was a red herring for us. At the moment, I'm not aware of any version combination that works reliably with deep trees of mixed Immutables, e.g., Map.Map.OrderedSet.Map. Rehydration always breaks something somewhere. 4.6.0 + 4.2.0 doesn't seem to help either, although it's hard to say because an area that rehydrates incorrectly one day, will seemingly work the next.
Any alternatives or workarounds others have found?
+1
+1
just published 4.3.0 with immutable as a peer dep and updated transit deps. Hopefully this helps the situation.
No - List is still rehydrating as a Map with v4.3.0.