Created
December 19, 2018 08:33
-
-
Save ger86/36ec5c6dfeed4be0f71a17a7ea0b6d9a to your computer and use it in GitHub Desktop.
configureStoreWithFSStorage.js
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 { createStore, applyMiddleware } from 'redux'; | |
| import reduxThunk from 'redux-thunk'; | |
| import RNFS from 'react-native-fs'; | |
| import { Platform } from 'react-native'; | |
| import { persistStore, persistReducer } from 'redux-persist'; | |
| import FSStorage from 'redux-persist-fs-storage'; | |
| import rootReducer from 'WorthymApp/src/ducks'; | |
| const getFSStorage = () => | |
| Platform.OS === 'ios' | |
| ? RNFS.pathForGroup('group.app.appName').then(folder => FSStorage(folder)) | |
| : Promise.resolve(FSStorage()); | |
| const configureStore = callback => | |
| getFSStorage().then(fsStorage => { | |
| const persistConfig = { | |
| key: 'root', | |
| storage: fsStorage, | |
| blacklist: ['form'] | |
| }; | |
| const persistedReducer = persistReducer(persistConfig, rootReducer); | |
| const createStoreWithMiddleware = applyMiddleware(reduxThunk)(createStore); | |
| const store = createStoreWithMiddleware(persistedReducer); | |
| const persistor = persistStore(store, null, () => callback(store)); | |
| return { store, persistor }; | |
| }); | |
| export default configureStore; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment