Created
April 30, 2017 06:44
-
-
Save malexsan1/c5b1b168a80712188bae19c0f18b60df to your computer and use it in GitHub Desktop.
Redux Persist cache busting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { AsyncStorage } from 'react-native' | |
const reducerVersion ='1' //manually change the reducer version to cache bust | |
const config = { | |
storage: AsyncStorage | |
} | |
const updateReducers = (store) => { | |
const startup = () => console.log('Do something after local storage has been updated.') | |
// Check to ensure latest reducer version | |
AsyncStorage.getItem('reducerVersion').then((localVersion) => { | |
if (localVersion !== reducerVersion) { | |
// Purge store | |
persistStore(store, config, startup).purge() | |
//save the new reducer version in the local cache | |
AsyncStorage.setItem('reducerVersion', reducerVersion) | |
} else { | |
persistStore(store, config, startup) | |
} | |
}).catch(() => { | |
persistStore(store, config, startup) | |
AsyncStorage.setItem('reducerVersion', reducerVersion) | |
}) | |
} | |
export { | |
updateReducers | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment