Created
May 7, 2020 05:24
-
-
Save MrKou47/fefb805af728fca301612a9db60b3ebb to your computer and use it in GitHub Desktop.
awesome composite by typescript and redux
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createStore, combineReducers, applyMiddleware, compose } from 'redux'; | |
import thunk from 'redux-thunk'; | |
import { request } from './utils/utils'; | |
import accountlist from './containers/AccountList/reducer'; | |
import withdraworder from './containers/WithdrawOrder/reducer'; | |
const userInitialState = { | |
} | |
const userReducer = (state = userInitialState) => state; | |
const reducer = { | |
accountlist, | |
withdraworder, | |
userinfo: userReducer, | |
}; | |
type GetReturnType<original extends Function> = | |
original extends (...x: any[]) => infer returnType ? returnType : never | |
export type IFnReturnType<T> = { | |
[P in keyof T]: T[P] extends Function ? GetReturnType<T[P]> : T[P]; | |
}; | |
export type IRootStateType = IFnReturnType<typeof reducer>; | |
const composeEnhancers = (window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose; | |
const combinedReducer = combineReducers(reducer); | |
const store = createStore( | |
combinedReducer, | |
composeEnhancers( | |
applyMiddleware( | |
thunk.withExtraArgument({ request: request() }) | |
) | |
) | |
); | |
export default store; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment