// @flow
// builds the store and fetches the objects
import { createStore, applyMiddleware, compose } from 'redux';
import reducer from './reducers';
import type { State } from './reducers';
import thunk from 'redux-thunk';

const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;

const createStoreFunc = (preloadedState?: State) => {
	return preloadedState ?
		createStore(
			reducer,
			preloadedState,
			composeEnhancers(
				applyMiddleware(
					thunk,
				),
			),
		)
		:
		createStore(
			reducer,
			composeEnhancers(
				applyMiddleware(
					thunk,
				),
			),
		);
};

export default createStoreFunc;
