2020-09-23 18:13:01 +00:00
|
|
|
import {
|
|
|
|
configureStore,
|
|
|
|
Action,
|
|
|
|
getDefaultMiddleware,
|
|
|
|
Middleware,
|
|
|
|
Dispatch,
|
|
|
|
} 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";
|
2020-04-03 14:23:03 +00:00
|
|
|
import {
|
2020-04-19 13:47:19 +00:00
|
|
|
mixerMiddleware,
|
2020-04-19 16:33:34 +00:00
|
|
|
mixerKeyboardShortcutsMiddleware,
|
2021-05-31 20:48:38 +00:00
|
|
|
startNewsTimer,
|
2020-04-03 14:23:03 +00:00
|
|
|
} from "./mixer/state";
|
2020-09-23 00:11:53 +00:00
|
|
|
import {
|
|
|
|
persistStore,
|
|
|
|
FLUSH,
|
|
|
|
REHYDRATE,
|
|
|
|
PAUSE,
|
|
|
|
PERSIST,
|
|
|
|
PURGE,
|
2020-09-23 18:13:01 +00:00
|
|
|
REGISTER,
|
2020-09-23 00:11:53 +00:00
|
|
|
} from "redux-persist";
|
2020-11-14 08:59:23 +00:00
|
|
|
import { bapsicleMiddleware } from "./bapsicle";
|
2020-09-23 00:11:53 +00:00
|
|
|
|
2020-10-06 12:29:06 +00:00
|
|
|
const ACTION_HISTORY_MAX_SIZE = 20;
|
|
|
|
|
|
|
|
const actionHistory: Array<Action> = [];
|
|
|
|
|
|
|
|
const actionHistoryMiddleware: Middleware<{}, RootState, Dispatch<any>> = (
|
|
|
|
store
|
|
|
|
) => (next) => (action) => {
|
|
|
|
while (actionHistory.length > ACTION_HISTORY_MAX_SIZE) {
|
|
|
|
actionHistory.shift();
|
|
|
|
}
|
2020-10-06 12:31:31 +00:00
|
|
|
actionHistory.push({
|
|
|
|
...action,
|
|
|
|
_timestamp: new Date().toString(),
|
|
|
|
});
|
2020-09-23 00:11:53 +00:00
|
|
|
return next(action);
|
2020-09-23 18:13:01 +00:00
|
|
|
};
|
2019-11-26 10:01:26 +00:00
|
|
|
|
2020-10-06 12:29:06 +00:00
|
|
|
export function getActionHistory() {
|
|
|
|
return actionHistory;
|
|
|
|
}
|
|
|
|
|
2020-09-23 00:11:53 +00:00
|
|
|
// See https://github.com/rt2zz/redux-persist/issues/988 for getDefaultMiddleware tweak.
|
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-11-14 08:59:23 +00:00
|
|
|
bapsicleMiddleware,
|
2020-10-06 12:29:06 +00:00
|
|
|
actionHistoryMiddleware,
|
2020-09-23 00:11:53 +00:00
|
|
|
...getDefaultMiddleware({
|
|
|
|
serializableCheck: {
|
2020-09-23 18:13:01 +00:00
|
|
|
ignoredActions: [FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER],
|
|
|
|
},
|
|
|
|
}),
|
2020-04-19 16:33:34 +00:00
|
|
|
],
|
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
|
|
|
}
|
|
|
|
|
2020-04-10 08:04:42 +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>>;
|
2020-05-07 11:05:52 +00:00
|
|
|
|
2021-05-31 20:48:38 +00:00
|
|
|
if (!process.env.REACT_APP_BAPSICLE_INTERFACE) {
|
|
|
|
store.dispatch(startNewsTimer() as any);
|
|
|
|
}
|
|
|
|
|
2019-11-26 10:01:26 +00:00
|
|
|
export default store;
|