import { createStore,compose } from 'redux';
import reducers from './reducers/reducers';
import { saveState } from './persisted.store.cookies.js';

export default function configureStore(initialState) {

    const enhancers = compose(
        (typeof window !== 'undefined' && window.devToolsExtension) ? window.devToolsExtension() : f => f
      );


    const store = createStore(reducers, {
        ...initialState
    },
    enhancers
    );

    // add a listener that will be invoked on any state change
    store.subscribe(() => {
        saveState(store.getState());
    });

    return store;
}
