WebStudio/src/store.ts

40 lines
1.1 KiB
TypeScript
Raw Normal View History

2020-05-10 12:00:03 +00:00
import raygun from "raygun4js";
2020-03-19 22:24:00 +00:00
import { configureStore, Action, getDefaultMiddleware } from "@reduxjs/toolkit";
2020-05-05 18:41:29 +00:00
import rootReducer, { RootState } from "./rootReducer";
2019-11-26 10:01:26 +00:00
import { ThunkAction } from "redux-thunk";
import {
2020-04-19 13:47:19 +00:00
mixerMiddleware,
2020-04-19 16:33:34 +00:00
mixerKeyboardShortcutsMiddleware,
startNewsTimer,
} from "./mixer/state";
import { persistStore } from "redux-persist";
2019-11-26 10:01:26 +00:00
const store = configureStore({
2020-04-19 13:47:19 +00:00
reducer: rootReducer,
middleware: [
mixerMiddleware,
mixerKeyboardShortcutsMiddleware,
2020-05-10 12:00:03 +00:00
(store) => (next) => (action) => {
raygun("recordBreadcrumb", "redux-action", action);
2020-05-05 18:41:29 +00:00
return next(action);
},
2020-04-19 16:33:34 +00:00
...getDefaultMiddleware(),
],
2019-11-26 10:01:26 +00:00
});
if (process.env.NODE_ENV === "development" && module.hot) {
2020-04-19 13:47:19 +00:00
module.hot.accept("./rootReducer", () => {
const newRootReducer = require("./rootReducer").default;
store.replaceReducer(newRootReducer);
});
2019-11-26 10:01:26 +00:00
}
export const persistor = persistStore(store);
2019-11-26 10:01:26 +00:00
export type AppDispatch = typeof store.dispatch;
export type AppThunk = ThunkAction<void, RootState, null, Action<string>>;
store.dispatch(startNewsTimer() as any);
2019-11-26 10:01:26 +00:00
export default store;