import {
    createStore,
    applyMiddleware
} from 'redux';
import thunkMiddleware from 'redux-thunk';
import {
    createLogger
} from 'redux-logger';
import reduxCatch from 'redux-catch';
import wiaasReducers from './reducers';

const loggerMiddleware = createLogger();
const errorHandler = (error, getState, lastAction, dispatch) => {
    console.error(error);
    console.debug('current state', getState());
    console.debug('last action was', lastAction);
};

function configureStore() {
    return createStore(
        wiaasReducers,
        applyMiddleware(
            reduxCatch(errorHandler),
            thunkMiddleware,
            loggerMiddleware
        )
    )
}


export let store = configureStore();
