import { persistStore, persistReducer } from 'redux-persist';
import { AsyncStorage } from 'react-native'
const createPersistStore = (rootReducer, createStore)=>{
const persistConfig = {
key: 'root',
storage: AsyncStorage
}
const persistedReducer = persistReducer(persistConfig, rootReducer)
return createStore(persistedReducer);
}
const StoreEnhancer = () => (createStore)=> (rootReducer, prevState)=> createPersistStore(rootReducer, createStore);
const app = dva({
extraEnhancers: [
StoreEnhancer(),
applyMiddleware(middleware)
],
}
const MainApp = app.start(<App />);
persistStore(app.getStore() , { storage : AsyncStorage }, (err, res)=>{
console.log(err, res, app);
const state = app._store.getState();
const { system : { isFirst, doLogin }} = state;
if(isFirst) {
app._store.dispatch({
type: 'system/resetPage',
payload: 'Welcome'
})
} else if(doLogin) {
app._store.dispatch({
type: 'system/resetPage',
payload: 'UserLogin'
})
}
});