Skip to content

Instantly share code, notes, and snippets.

@MrKou47
Created May 7, 2020 05:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MrKou47/fefb805af728fca301612a9db60b3ebb to your computer and use it in GitHub Desktop.
Save MrKou47/fefb805af728fca301612a9db60b3ebb to your computer and use it in GitHub Desktop.
awesome composite by typescript and redux
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