37 lines
1 KiB
JavaScript
37 lines
1 KiB
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';
|
|
import actionChain from './middleware/actionChain';
|
|
|
|
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,
|
|
actionChain,
|
|
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;
|
|
}
|