Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Record rehydrating as a map #21

Open
eamonpenland opened this issue Mar 8, 2017 · 11 comments
Open

Record rehydrating as a map #21

eamonpenland opened this issue Mar 8, 2017 · 11 comments

Comments

@eamonpenland
Copy link

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?

@rt2zz
Copy link
Owner

rt2zz commented Mar 15, 2017

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!

@rynbyjn
Copy link

rynbyjn commented Apr 7, 2017

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.

@ndbroadbent
Copy link

@rynbyjn I just noticed this was happening for me too. Thanks for the tip!

@rt2zz
Copy link
Owner

rt2zz commented Apr 14, 2017

that is unfortunate. @rynbyjn what do you recommend for solving this at the lib level?

@rt2zz
Copy link
Owner

rt2zz commented Apr 14, 2017

seems this might best be solved by making immutablejs a peer dep..

@ylg
Copy link

ylg commented Apr 16, 2017

It's early days, but for the moment I was able to resolve this in our apps by requiring react-redux >= 5.0.4.

@ylg
Copy link

ylg commented Apr 26, 2017

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?

@cbjs
Copy link

cbjs commented May 2, 2017

+1

1 similar comment
@formatlos
Copy link

+1

@rt2zz
Copy link
Owner

rt2zz commented May 4, 2017

just published 4.3.0 with immutable as a peer dep and updated transit deps. Hopefully this helps the situation.

@peterorum
Copy link

No - List is still rehydrating as a Map with v4.3.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants