[Improvement] Add config store for different environments
This commit is contained in:
27
src/store/configureStore.dev.ts
Normal file
27
src/store/configureStore.dev.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
// - Import external components
|
||||
import * as redux from 'redux'
|
||||
import thunk from 'redux-thunk'
|
||||
import { routerMiddleware } from 'react-router-redux'
|
||||
import createHistory from 'history/createBrowserHistory'
|
||||
import { createLogger } from 'redux-logger'
|
||||
import { rootReducer } from 'reducers'
|
||||
|
||||
// Create a history of your choosing (we're using a browser history in this case)
|
||||
export const history = createHistory()
|
||||
|
||||
// - Build the middleware for intercepting and dispatching navigation actions
|
||||
const middleware = routerMiddleware(history)
|
||||
const logger = createLogger()
|
||||
|
||||
// - initial state
|
||||
let initialState = {
|
||||
|
||||
}
|
||||
|
||||
// - Config and create store of redux
|
||||
let store: redux.Store<any> = redux.createStore(rootReducer, initialState, redux.compose(
|
||||
redux.applyMiddleware(logger,thunk,middleware),
|
||||
(window as any).devToolsExtension ? (window as any).devToolsExtension() : (f: any) => f
|
||||
))
|
||||
|
||||
export default store
|
||||
25
src/store/configureStore.prod.ts
Normal file
25
src/store/configureStore.prod.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
// - Import external components
|
||||
import * as redux from 'redux'
|
||||
import thunk from 'redux-thunk'
|
||||
import { routerMiddleware } from 'react-router-redux'
|
||||
import createHistory from 'history/createBrowserHistory'
|
||||
import { rootReducer } from 'reducers'
|
||||
|
||||
// Create a history of your choosing (we're using a browser history in this case)
|
||||
export const history = createHistory()
|
||||
|
||||
// - Build the middleware for intercepting and dispatching navigation actions
|
||||
const middleware = routerMiddleware(history)
|
||||
|
||||
// - initial state
|
||||
let initialState = {
|
||||
|
||||
}
|
||||
|
||||
// - Config and create store of redux
|
||||
let store: redux.Store<any> = redux.createStore(rootReducer, initialState, redux.compose(
|
||||
redux.applyMiddleware(thunk,middleware),
|
||||
(window as any).devToolsExtension ? (window as any).devToolsExtension() : (f: any) => f
|
||||
))
|
||||
|
||||
export default store
|
||||
@@ -1,27 +1,8 @@
|
||||
// - Import external components
|
||||
import * as redux from 'redux'
|
||||
import thunk from 'redux-thunk'
|
||||
import { routerMiddleware } from 'react-router-redux'
|
||||
import createHistory from 'history/createBrowserHistory'
|
||||
import { createLogger } from 'redux-logger'
|
||||
import { rootReducer } from 'reducers'
|
||||
import configureStoreDev from './configureStore.dev'
|
||||
import configureStoreProd from './configureStore.prod'
|
||||
|
||||
// Create a history of your choosing (we're using a browser history in this case)
|
||||
export const history = createHistory()
|
||||
const store = process.env.NODE_ENV === 'production'
|
||||
? configureStoreDev
|
||||
: configureStoreProd
|
||||
|
||||
// - Build the middleware for intercepting and dispatching navigation actions
|
||||
const middleware = routerMiddleware(history)
|
||||
const logger = createLogger()
|
||||
|
||||
// - initial state
|
||||
let initialState = {
|
||||
|
||||
}
|
||||
|
||||
// - Config and create store of redux
|
||||
let store: redux.Store<any> = redux.createStore(rootReducer, initialState, redux.compose(
|
||||
redux.applyMiddleware(logger,thunk,middleware),
|
||||
(window as any).devToolsExtension ? (window as any).devToolsExtension() : (f: any) => f
|
||||
))
|
||||
|
||||
export default store
|
||||
export default store
|
||||
Reference in New Issue
Block a user