Skip to content

Commit

Permalink
persist: Refactor slightly to look more like v5-using code.
Browse files Browse the repository at this point in the history
This is a pure refactor that just reorganizes the code slightly.  This
version is perhaps cleaner in itself; but what really motivates the
change is to make it look more like what we'll have for using
redux-persist v5, to shrink the upcoming diff that does that.

Based on @roberthoenig's drafts in #2762 of the redux-persist upgrade.
  • Loading branch information
gnprice committed Aug 3, 2018
1 parent 6f703dc commit aac5eb5
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/boot/store.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* @flow */
import { applyMiddleware, compose, createStore } from 'redux';
import { persistStore, autoRehydrate } from 'redux-persist';
import type { Config } from 'redux-persist';

import config from '../config';
import rootReducer from './reducers';
Expand All @@ -17,15 +18,13 @@ import ZulipAsyncStorage from './ZulipAsyncStorage';

const store = compose(applyMiddleware(...middleware), autoRehydrate())(createStore)(rootReducer);

const reduxPersistConfig: Config = {
whitelist: [...config.storeKeys, ...config.cacheKeys],
// $FlowFixMe: https://github.com/rt2zz/redux-persist/issues/823
storage: ZulipAsyncStorage,
};

export const restore = (onFinished?: () => void) =>
persistStore(
store,
{
whitelist: [...config.storeKeys, ...config.cacheKeys],
// $FlowFixMe: https://github.com/rt2zz/redux-persist/issues/823
storage: ZulipAsyncStorage,
},
onFinished,
);
persistStore(store, reduxPersistConfig, onFinished);

export default store;

0 comments on commit aac5eb5

Please sign in to comment.