import { createStore, applyMiddleware } from 'redux'
import * as storage from 'redux-storage'
import thunk from 'redux-thunk';
import promise from 'redux-promise';
import createLogger from 'redux-logger'
import createEngine from 'redux-storage/engines/reactNativeAsyncStorage'
import rootReducer from './reducers'

// setup persistence middleware
const reducer = storage.reducer(rootReducer)
const engine = createEngine('havit-save-key')
const persistence = storage.createMiddleware(engine)

const logger = createLogger()
const createStoreWithMiddleware = applyMiddleware(thunk, promise, persistence, logger)(createStore)

const store = createStoreWithMiddleware(reducer)
const load = storage.createLoader(engine)

// load persisted state back into store
load(store)
    .then(console.log('Loaded previous state'))
    .catch(() => console.log('Failed to load previous state'))

export default store;

@@ -83,24 +83,67 @@
 ux-storage'%0A
+import %7B decorators %7D from 'redux-storage'%0A
 import thunk
@@ -163,16 +163,16 @@
 thunk';%0A
-
 import p
@@ -383,16 +383,17 @@
 dleware%0A
+%0A
 const re
@@ -429,20 +429,18 @@
 educer)%0A
-cons
+le
 t engine
@@ -473,16 +473,63 @@
 e-key')%0A
+engine = decorators.filter(engine, %5B'auth'%5D);%0A%0A
 const pe
@@ -880,32 +880,37 @@
 Loaded previous 
+auth 
 state'))%0A    .ca
@@ -956,16 +956,21 @@
 revious 
+auth 
 state'))

whitelist which keys to persist from the redux store