import {
  configureStore,
} from '@reduxjs/toolkit';
import { useDispatch, useSelector} from 'react-redux';
import injectReducerEnhancer from "../utils/@reduxjs/injectReducer/enhancer";
import rejectedErrorHandlerMiddleware from '../utils/@reduxjs/rejectedErrorHandlerMiddleware';
import {createReducer} from './reducers';


/**
 * 创建store并装载 reducer自动注入中间件
 */
export const store = configureStore({
  reducer: createReducer(),
  devTools: process.env.NODE_ENV !== 'production' || process.env.PUBLIC_URL !== "",
  enhancers: getDefaultEnhancers => getDefaultEnhancers().concat(injectReducerEnhancer(createReducer)),
  // @ts-ignore
  middleware: getDefaultMiddleware =>
    getDefaultMiddleware({
      serializableCheck: false,
      // immutableCheck: false,
    }).prepend(rejectedErrorHandlerMiddleware.middleware)
});

// you can also create some redux hooks using the above explicit types
export const useAppDispatch = () => useDispatch();
export const useAppSelector = useSelector;
