diff --git a/src/index.tsx b/src/index.tsx index 9f7697b..875753b 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -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(), }; }); diff --git a/src/store.ts b/src/store.ts index adc5347..18274d6 100644 --- a/src/store.ts +++ b/src/store.ts @@ -23,20 +23,34 @@ import { REGISTER, } from "redux-persist"; -const raygunMiddleware: Middleware<{}, RootState, Dispatch> = (store) => ( - next -) => (action) => { - raygun("recordBreadcrumb", "redux-action", action); +const ACTION_HISTORY_MAX_SIZE = 20; + +const actionHistory: Array = []; + +const actionHistoryMiddleware: Middleware<{}, RootState, Dispatch> = ( + 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],