Skip to content

Instantly share code, notes, and snippets.

@calvinfroedge
Created May 1, 2016 20:09
Show Gist options
  • Save calvinfroedge/9844504b9ee81ef645b80a402f2ab42b to your computer and use it in GitHub Desktop.
Save calvinfroedge/9844504b9ee81ef645b80a402f2ab42b to your computer and use it in GitHub Desktop.
Redux setup function
import React from 'react'
//Redux DevTools
import { createDevTools } from 'redux-devtools'
import LogMonitor from 'redux-devtools-log-monitor'
import DockMonitor from 'redux-devtools-dock-monitor'
//React-Router
import { browserHistory } from 'react-router'
import { syncHistoryWithStore, routerReducer, routerMiddleware } from 'react-router-redux'
//Redux
import { applyMiddleware, compose, createStore, combineReducers } from 'redux'
export default function(reducers={}, middlewares=[]){
//Set up Redux Middleware
const reducer = combineReducers({
...reducers,
routing: routerReducer
})
//Set up Dev Tools
const DevTools = createDevTools(
<DockMonitor toggleVisibilityKey="ctrl-h"
changePositionKey="ctrl-q">
<LogMonitor theme="tomorrow" preserveScrollTop={false} />
</DockMonitor>
)
//Create the store
let middlewareToApply = applyMiddleware(...middlewares, routerMiddleware(browserHistory))
const finalCreateStore = compose(
middlewareToApply,
DevTools.instrument()
)(createStore)
const store = finalCreateStore(reducer)
const history = syncHistoryWithStore(browserHistory, store)
return {
DevTools,
store,
history
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment