Merge pull request #157 from UniversityRadioYork/marks-raygun-redux2
Save limited action history for Raygun reports
This commit is contained in:
commit
999b7fefc5
2 changed files with 21 additions and 6 deletions
|
@ -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(),
|
||||
};
|
||||
});
|
||||
|
||||
|
|
24
src/store.ts
24
src/store.ts
|
@ -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],
|
||||
|
|
Loading…
Reference in a new issue