Skip to content

Commit 8d8bf9d

Browse files
committed
Trying to combat redux devtools crashing
Before crashing it at least complains it is going to be slow and consume a huge amount of memory. That is described here: https://github.com/zalmoxisus/redux-devtools-extension/blob/master/docs/Troubleshooting.md#excessive-use-of-memory-and-cpu In there is a link to a more useful example: zalmoxisus/redux-devtools-extension#455 Latest conversation seems to be here: zalmoxisus/redux-devtools-extension#619 Signed-off-by: michael sorens <[email protected]>
1 parent 0d14694 commit 8d8bf9d

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

components/automate-ui/src/app/app.module.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { StoreDevtoolsModule } from '@ngrx/store-devtools';
1717
import { StoreModule } from '@ngrx/store';
1818
import { StoreRouterConnectingModule } from '@ngrx/router-store';
1919
import { NgrxEffectsModule } from './ngrx.effects';
20-
import { ngrxReducers, RouterSerializer, runtimeChecks } from './ngrx.reducers';
20+
import { ngrxReducers, RouterSerializer, runtimeChecks, actionSanitizer, stateSanitizer } from './ngrx.reducers';
2121

2222
// angular material stuff
2323
import {
@@ -284,7 +284,8 @@ import { WelcomeModalComponent } from './page-components/welcome-modal/welcome-m
284284
StoreRouterConnectingModule.forRoot({
285285
serializer: RouterSerializer
286286
}),
287-
!environment.production ? StoreDevtoolsModule.instrument({ maxAge: 25 }) : []
287+
environment.production ? []
288+
: StoreDevtoolsModule.instrument({ maxAge: 25 /* states */, actionSanitizer, stateSanitizer })
288289
],
289290
providers: [
290291
AdminKeyRequests,

components/automate-ui/src/app/ngrx.reducers.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,3 +304,26 @@ export const ngrxReducers = {
304304
users: userEntity.userEntityReducer,
305305
userSelf: userSelfEntity.userSelfEntityReducer
306306
};
307+
308+
export const actionSanitizer = action => {
309+
const uiRouterActions = /@ui-router.+/g;
310+
return uiRouterActions.test(action.type)
311+
? { type: action.type, transition: sanitizeUIRouterTransition(action.transition) }
312+
: action;
313+
};
314+
export const stateSanitizer = (state): any => {
315+
if (state.router && state.router.last && state.router.last) {
316+
return {
317+
...state,
318+
router: sanitizeUIRouterTransition(state.router.last)
319+
};
320+
}
321+
return state;
322+
};
323+
const sanitizeUIRouterTransition = (transition): any => ({
324+
params: transition.router && transition.router.globals && transition.router.globals.params,
325+
current: transition.router && transition.router.globals && transition.router.globals.current,
326+
targetState: transition.targetState && transition.targetState().state(),
327+
from: transition.from && transition.from(),
328+
to: transition.to && transition.to()
329+
});

0 commit comments

Comments
 (0)