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

Expire on all reducers at once #5

Open
rafatwork opened this issue May 18, 2017 · 1 comment
Open

Expire on all reducers at once #5

rafatwork opened this issue May 18, 2017 · 1 comment

Comments

@rafatwork
Copy link

Thank you for this functionality, is working great.

I was wondering: you now have to set an expire date on each reducer separately. In my use case, I just have to expire all the persisted data, regardless of which reducer it's part of. Is there a way of doing that?

@gabceb
Copy link
Owner

gabceb commented Oct 19, 2017

Hi! Sorry for the super late response to this but better late than never I hope. See code below on what I use to purge a reducer completely. The imported reducerVersion is just a static variable that can be increased on new builds

import ReduxPersist from '../config/ReduxPersist';
import { AsyncStorage } from 'react-native';
import { persistStore } from 'redux-persist';
import { startup as startupAction } from '../modules/Startup';

const updateReducers = (store: Object) => {
  const reducerVersion = ReduxPersist.reducerVersion;
  const config = ReduxPersist.storeConfig;
  const startup = () => store.dispatch(startupAction());

  // Check to ensure latest reducer version
  AsyncStorage.getItem('reducerVersion').then((localVersion) => {
    if (localVersion !== reducerVersion) {
      // Purge store
      persistStore(store, config, startup).purge();
      AsyncStorage.setItem('reducerVersion', reducerVersion);
    } else {
      persistStore(store, config, startup);
    }
  }).catch(() => {
    persistStore(store, config, startup);
    AsyncStorage.setItem('reducerVersion', reducerVersion);
  });
};

export default {updateReducers};

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