You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1.0 KiB
35 lines
1.0 KiB
// @flow
|
|
|
|
import { createStore, applyMiddleware, compose } from 'redux'
|
|
import { routerMiddleware } from 'react-router-redux'
|
|
import thunk from 'redux-thunk'
|
|
import createHistory from 'history/createHashHistory'
|
|
import type { HashHistory } from 'history'
|
|
import logger from 'middlewares/logger'
|
|
import reducers from 'reducers'
|
|
|
|
type Props = {
|
|
history: HashHistory,
|
|
state?: Object,
|
|
history?: any,
|
|
dbMiddleware?: Function,
|
|
}
|
|
|
|
export default ({ state, history, dbMiddleware }: Props) => {
|
|
if (!history) {
|
|
history = createHistory()
|
|
}
|
|
const middlewares = [routerMiddleware(history), thunk, logger]
|
|
if (!process.env.STORYBOOK_ENV) {
|
|
middlewares.push(require('middlewares/sentry').default)
|
|
middlewares.push(require('middlewares/analytics').default)
|
|
}
|
|
if (dbMiddleware) {
|
|
middlewares.push(dbMiddleware)
|
|
}
|
|
const enhancers = compose(
|
|
applyMiddleware(...middlewares),
|
|
window.devToolsExtension ? window.devToolsExtension() : f => f, // eslint-disable-line
|
|
)
|
|
return createStore(reducers, state, enhancers)
|
|
}
|
|
|