Skip to content

Instantly share code, notes, and snippets.

@mbret
Created September 26, 2019 05:10
Show Gist options
  • Save mbret/511edf9627b743ad8a52559be61e3d45 to your computer and use it in GitHub Desktop.
Save mbret/511edf9627b743ad8a52559be61e3d45 to your computer and use it in GitHub Desktop.
// we have a LOGOUT action that will reset the whole state
// HACK: When state is recreated, it will loose '_persist' in it, and the state will not be persisted anymore.
// Dispatching 'persist/REHYDRATE' makes persistence work again somehow, so we dispatch it to all persisted keys.
const storageKeys = yield call(storage.getAllKeys);
const persistKeys = (storageKeys.map((key: string) => {
const regexp = new RegExp('^persist:(.+)');
if (key.match(regexp)) {
return RegExp.$1;
}
return '';
}) as string[]).filter(key => key !== '');
const persistActions = persistKeys.map(key => put({
type: 'persist/REHYDRATE', key, payload: undefined,
}));
yield all(persistActions);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment