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

Doesn't work with redux-persist-immutable #8

Open
laurib opened this issue Feb 6, 2017 · 1 comment
Open

Doesn't work with redux-persist-immutable #8

laurib opened this issue Feb 6, 2017 · 1 comment

Comments

@laurib
Copy link

laurib commented Feb 6, 2017

rehydrate gives error state.forEach is not a function

@laurib
Copy link
Author

laurib commented Feb 7, 2017

I solved problem with this quick fix

import { getStoredState } from 'redux-persist-immutable';

export const crosstabSync = (persistor, config) => {
  config = config || {}
  let blacklist = config.blacklist || false;
  let whitelist = config.whitelist || false;

  const handleStorageEvent = (e) => {
    if(e.key.indexOf(KEY_PREFIX) === 0){
      var keyspace = e.key.substr(KEY_PREFIX.length);
      if(whitelist && whitelist.indexOf(keyspace) === -1){ return }
      if(blacklist && blacklist.indexOf(keyspace) !== -1){ return }


      getStoredState(persistConfig, (err, state) => {
        var statePartial = {}
        statePartial[keyspace] = state[keyspace];
        persistor.rehydrate(statePartial);
      })
    }
  }

  window.addEventListener('storage', handleStorageEvent, false);
}

I don't use auto autoRehydrate()

example of updating my session reducer

case 'persist/REHYDRATE':
      return state.merge(action.payload.session);

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

1 participant