36 lines
962 B
JavaScript
36 lines
962 B
JavaScript
|
import { createStore, applyMiddleware } from 'redux';
|
||
|
import reducers from './reducers';
|
||
|
|
||
|
import settings from './settings/constants';
|
||
|
import * as storage from 'redux-storage';
|
||
|
import createEngine from 'redux-storage-engine-reactnativeasyncstorage';
|
||
|
import filter from 'redux-storage-decorator-filter';
|
||
|
|
||
|
import { apiMiddleware } from 'redux-api-middleware';
|
||
|
|
||
|
const engine = filter(createEngine(settings.get('STORAGE_KEY')));
|
||
|
|
||
|
const storeMiddleware = storage.createMiddleware(engine);
|
||
|
|
||
|
|
||
|
export default function configureStore(initialState) {
|
||
|
const load = storage.createLoader(engine);
|
||
|
|
||
|
const createStoreWithMiddleware = applyMiddleware(
|
||
|
apiMiddleware,
|
||
|
storeMiddleware // Last in list
|
||
|
)(createStore);
|
||
|
|
||
|
const store = createStoreWithMiddleware(reducers);
|
||
|
|
||
|
load(store)
|
||
|
.then(function (newData) {
|
||
|
console.log('LOADED STATE');
|
||
|
})
|
||
|
.catch(function () {
|
||
|
console.log('FAILED TO LOAD STATE', arguments);
|
||
|
});
|
||
|
|
||
|
return store;
|
||
|
}
|