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

redux-persist-immutable tries to parse state object as json #23

Open
ghost opened this issue Feb 23, 2017 · 2 comments
Open

redux-persist-immutable tries to parse state object as json #23

ghost opened this issue Feb 23, 2017 · 2 comments

Comments

@ghost
Copy link

ghost commented Feb 23, 2017

When trying to configure redux-persist-immutable, it fails with unexpected token o in json at position 1 which indicates to me that something is trying to parse an object as JSON. Tracing the code down, I found that redux-persist-transform-immutable/index.js is expecting JSON when it creates its transformers. I modified their code to transform raw into JSON right before it transforms it, and the error goes away; however, the data does not get autoRehydrated.

Here is how I've implemented redux-persist-immutable, right before I hand the store over to <Provider> I have more reducers, but I've trimmed it down for brevity.

store.js
import { AsyncStorage } from 'react-native';
import { fromJS } from 'immutable';
import { compose, applyMiddleware, createStore } from 'redux';
import { combineReducers } from 'redux-immutable';
import { persistStore, autoRehydrate } from 'redux-persist-immutable';
import createSagaMiddleware from 'redux-saga';
import logger from 'redux-logger';
import sagas from './sagas';

import appReducer from './containers/App/reducer';

export default function configureStore(initialState = {}) {
  // Middleware
  const sagaMiddleware = createSagaMiddleware({
    logger: () => {},
  });
  const middlewares = [
    sagaMiddleware,
    logger(),
  ];
  const enhancers = [
    applyMiddleware(...middlewares),
  ];

  const store = createStore(
    combineReducers({
      global: appReducer,
    }),
    fromJS(initialState),
    compose(...enhancers)
  );

  sagas.map((container) => {
    container.map((sagaGroup) =>{
      sagaMiddleware.run(sagaGroup);
    });
  });

  persistStore(store, { storage: AsyncStorage });

  return store;
}
@sheraz-sarwar
Copy link

sheraz-sarwar commented May 22, 2017

Edit: Appears I should be using redux-persist-transform-immutable rather than redux-persist-immutable.

@rt2zz
Copy link
Owner

rt2zz commented May 22, 2017

this library should be able to handle both interchangeably. It may require an is immutable check on the top level and fallback to normal reconciliation. PR welcome!

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

2 participants