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'; import tokenInjector from './middleware/tokenInjector'; 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( tokenInjector, 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; }