-
-
Save igorjs/6ada8e22b0d2b5ebb7b2509880d181ab to your computer and use it in GitHub Desktop.
Custom redux persist version for redux-offline
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
//@flow | |
import { createStore, applyMiddleware } from 'redux'; | |
import storage from 'redux-persist/lib/storage' | |
import { composeWithDevTools } from 'redux-devtools-extension'; | |
import { persistStore, persistReducer } from 'redux-persist'; | |
import thunk from 'redux-thunk'; | |
import reducer from 'reducers'; | |
import { createOffline } from '@redux-offline/redux-offline'; | |
import offlineConfig from '@redux-offline/redux-offline/lib/defaults/index'; | |
const persistConfig = { | |
key: 'root', | |
storage | |
}; | |
const { | |
middleware: offlineMiddleware, | |
enhanceReducer: offlineEnhanceReducer, | |
enhanceStore: offlineEnhanceStore | |
} = createOffline({ | |
...offlineConfig, | |
persist: false | |
}); | |
const persistedReducer = persistReducer( | |
persistConfig, | |
offlineEnhanceReducer(reducer) | |
); | |
export default function configureStore() { | |
const store = createStore( | |
persistedReducer, | |
composeWithDevTools( | |
offlineEnhanceStore, | |
applyMiddleware(thunk, offlineMiddleware) | |
) | |
); | |
const persistor = persistStore(store); | |
return { persistor, store }; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment