Merge pull request #157 from UniversityRadioYork/marks-raygun-redux2

Save limited action history for Raygun reports
This commit is contained in:
Matthew Stratford 2020-10-26 22:28:08 +00:00 committed by GitHub
commit 999b7fefc5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 6 deletions

View file

@ -6,7 +6,7 @@ import * as serviceWorker from "./serviceWorkerLoader";
import raygun from "raygun4js";
import store from "./store";
import store, { getActionHistory } from "./store";
import { Provider } from "react-redux";
raygun("apiKey", "mtj24r3YzPoYyCG8cVArA");
@ -21,6 +21,7 @@ if (
raygun("withCustomData", function() {
return {
state: store.getState(),
actionHistory: getActionHistory(),
};
});

View file

@ -23,20 +23,34 @@ import {
REGISTER,
} from "redux-persist";
const raygunMiddleware: Middleware<{}, RootState, Dispatch<any>> = (store) => (
next
) => (action) => {
raygun("recordBreadcrumb", "redux-action", action);
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();
}
actionHistory.push({
...action,
_timestamp: new Date().toString(),
});
return next(action);
};
export function getActionHistory() {
return actionHistory;
}
// See https://github.com/rt2zz/redux-persist/issues/988 for getDefaultMiddleware tweak.
const store = configureStore({
reducer: rootReducer,
middleware: [
mixerMiddleware,
mixerKeyboardShortcutsMiddleware,
raygunMiddleware,
actionHistoryMiddleware,
...getDefaultMiddleware({
serializableCheck: {
ignoredActions: [FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER],