[Improvement] Add root reducer
This commit is contained in:
@@ -1,23 +1,5 @@
|
|||||||
import { authorizeReducer } from './authorize'
|
import {rootReducer} from './rootReducer'
|
||||||
import { circleReducer } from './circles'
|
|
||||||
import { commentReducer } from './comments'
|
|
||||||
import { globalReducer } from './global'
|
|
||||||
import { imageGalleryReducer } from './imageGallery'
|
|
||||||
import { notificationReducer } from './notifications'
|
|
||||||
import { postReducer } from './posts'
|
|
||||||
import { userReducer } from './users'
|
|
||||||
import { voteReducer } from './votes'
|
|
||||||
import { serverReducer } from './server'
|
|
||||||
|
|
||||||
export {
|
export {
|
||||||
authorizeReducer,
|
rootReducer
|
||||||
circleReducer,
|
|
||||||
commentReducer,
|
|
||||||
globalReducer,
|
|
||||||
imageGalleryReducer,
|
|
||||||
notificationReducer,
|
|
||||||
postReducer,
|
|
||||||
userReducer,
|
|
||||||
voteReducer,
|
|
||||||
serverReducer
|
|
||||||
}
|
}
|
||||||
|
|||||||
31
src/reducers/rootReducer.ts
Normal file
31
src/reducers/rootReducer.ts
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
import * as redux from 'redux'
|
||||||
|
import { localeReducer as locale } from 'react-localize-redux'
|
||||||
|
|
||||||
|
// - Import reducers
|
||||||
|
import { authorizeReducer } from './authorize'
|
||||||
|
import { circleReducer } from './circles'
|
||||||
|
import { commentReducer } from './comments'
|
||||||
|
import { globalReducer } from './global'
|
||||||
|
import { imageGalleryReducer } from './imageGallery'
|
||||||
|
import { notificationReducer } from './notifications'
|
||||||
|
import { postReducer } from './posts'
|
||||||
|
import { userReducer } from './users'
|
||||||
|
import { voteReducer } from './votes'
|
||||||
|
import { serverReducer } from './server'
|
||||||
|
import { routerReducer, routerMiddleware } from 'react-router-redux'
|
||||||
|
|
||||||
|
// - Reducers
|
||||||
|
export const rootReducer = redux.combineReducers({
|
||||||
|
locale,
|
||||||
|
imageGallery: imageGalleryReducer,
|
||||||
|
post: postReducer,
|
||||||
|
circle: circleReducer,
|
||||||
|
comment: commentReducer,
|
||||||
|
vote: voteReducer,
|
||||||
|
server: serverReducer,
|
||||||
|
authorize: authorizeReducer,
|
||||||
|
router: routerReducer,
|
||||||
|
user: userReducer,
|
||||||
|
notify: notificationReducer,
|
||||||
|
global: globalReducer
|
||||||
|
} as any)
|
||||||
@@ -1,24 +1,10 @@
|
|||||||
// - Import external components
|
// - Import external components
|
||||||
import * as redux from 'redux'
|
import * as redux from 'redux'
|
||||||
import thunk from 'redux-thunk'
|
import thunk from 'redux-thunk'
|
||||||
import { routerReducer, routerMiddleware } from 'react-router-redux'
|
import { routerMiddleware } from 'react-router-redux'
|
||||||
import createHistory from 'history/createBrowserHistory'
|
import createHistory from 'history/createBrowserHistory'
|
||||||
import { createLogger } from 'redux-logger'
|
import { createLogger } from 'redux-logger'
|
||||||
import { localeReducer as locale } from 'react-localize-redux'
|
import { rootReducer } from 'reducers'
|
||||||
|
|
||||||
// - Import reducers
|
|
||||||
import {
|
|
||||||
imageGalleryReducer,
|
|
||||||
postReducer,
|
|
||||||
commentReducer,
|
|
||||||
voteReducer,
|
|
||||||
serverReducer,
|
|
||||||
authorizeReducer,
|
|
||||||
globalReducer,
|
|
||||||
userReducer,
|
|
||||||
circleReducer,
|
|
||||||
notificationReducer
|
|
||||||
} from 'reducers'
|
|
||||||
|
|
||||||
// Create a history of your choosing (we're using a browser history in this case)
|
// Create a history of your choosing (we're using a browser history in this case)
|
||||||
export const history = createHistory()
|
export const history = createHistory()
|
||||||
@@ -27,29 +13,13 @@ export const history = createHistory()
|
|||||||
const middleware = routerMiddleware(history)
|
const middleware = routerMiddleware(history)
|
||||||
const logger = createLogger()
|
const logger = createLogger()
|
||||||
|
|
||||||
// - Reducers
|
|
||||||
let reducer = redux.combineReducers({
|
|
||||||
locale,
|
|
||||||
imageGallery: imageGalleryReducer,
|
|
||||||
post: postReducer,
|
|
||||||
circle: circleReducer,
|
|
||||||
comment: commentReducer,
|
|
||||||
vote: voteReducer,
|
|
||||||
server: serverReducer,
|
|
||||||
authorize: authorizeReducer,
|
|
||||||
router: routerReducer,
|
|
||||||
user: userReducer,
|
|
||||||
notify: notificationReducer,
|
|
||||||
global: globalReducer
|
|
||||||
} as any)
|
|
||||||
|
|
||||||
// - initial state
|
// - initial state
|
||||||
let initialState = {
|
let initialState = {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// - Config and create store of redux
|
// - Config and create store of redux
|
||||||
let store: redux.Store<any> = redux.createStore(reducer, initialState, redux.compose(
|
let store: redux.Store<any> = redux.createStore(rootReducer, initialState, redux.compose(
|
||||||
redux.applyMiddleware(logger,thunk,middleware),
|
redux.applyMiddleware(logger,thunk,middleware),
|
||||||
(window as any).devToolsExtension ? (window as any).devToolsExtension() : (f: any) => f
|
(window as any).devToolsExtension ? (window as any).devToolsExtension() : (f: any) => f
|
||||||
))
|
))
|
||||||
|
|||||||
Reference in New Issue
Block a user