Advertisement
Guest User

Untitled

a guest
May 5th, 2016
587
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //file ./store/configureStore.js
  2. 'use strict';
  3.  
  4. import {applyMiddleware, createStore} from 'redux';
  5. import thunk from 'redux-thunk';
  6. import reducers from '../reducers';
  7. import {persistStore, autoRehydrate} from 'redux-persist';
  8. import {AsyncStorage} from 'react-native';
  9.  
  10. var myStore = applyMiddleware(thunk)(createStore);
  11.  
  12. function configureStore(onComplete: ?() => void) {
  13.   const store = autoRehydrate()(myStore)(reducers);
  14.   persistStore(store, {storage: AsyncStorage, blacklist:['loginError']}, onComplete)
  15.  
  16.   return store;
  17. }
  18.  
  19. // File setup.js
  20. 'use strict';
  21.  
  22. import React from 'react-native';
  23. import App from './App';
  24.  
  25. import { Provider } from 'react-redux';
  26. import configureStore from './store/configureStore';
  27.  
  28. function setup() : React.Component {
  29.   class Root extends React.Component {
  30.     constructor() {
  31.       super();
  32.       this.state = {
  33.         isLoading: true,
  34.         // Note the callback
  35.         store: configureStore(() => this.setState({isLoading: false})),
  36.       };
  37.     }
  38.     render() {
  39.       if (this.state.isLoading) {
  40.         return null;
  41.       }
  42.       return (
  43.         <Provider store={this.state.store}>
  44.           <App />
  45.         </Provider>
  46.       );
  47.     }
  48.   }
  49.  
  50.   return Root;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement