summaryrefslogtreecommitdiff
path: root/scraper/client/store.js
blob: 043af351819db2d9ee3cfdaee5bf6a137e7c6a8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { applyMiddleware, compose, combineReducers, createStore } from 'redux'
import { connectRouter, routerMiddleware } from 'connected-react-router'
import { createBrowserHistory } from 'history'
import thunk from 'redux-thunk'
import { login } from './util'

import metadataReducer from './metadata/metadata.reducer'
import searchReducer from './search/search.reducer'
import reviewReducer from './review/review.reducer'

const rootReducer = combineReducers({
  auth: (state = login()) => state,
  metadata: metadataReducer,
  search: searchReducer,
  review: reviewReducer,
})

function configureStore(initialState = {}, history) {
  const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose

  const store = createStore(
    connectRouter(history)(rootReducer), // new root reducer with router state
    initialState,
    composeEnhancers(
      applyMiddleware(
        thunk,
        routerMiddleware(history)
      ),
    ),
  )

  return store
}

const history = createBrowserHistory()
const store = configureStore({}, history)

export { store, history }