Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(StoreDevtools): Add support for ActionSanitizer and StateSanitizer #795

Merged
merged 2 commits into from
Feb 12, 2018

Conversation

kgkma
Copy link
Contributor

@kgkma kgkma commented Feb 7, 2018

Continuing the work from #544 and requested by #604, this PR actually adds the sanitization functionality to @ngrx/store-devtools.

Unfortunately, simply passing actionSanitizer and stateSanitizer to the Redux Devtools Extension does not work, since the send(action, state) function exposed by its API does not sanitize anything if the action passed in is null, which is the current behaviour. As a result, it is necessary to sanitize within ngrx Devtools itself, and then pass that into the extension.

This implementation deliberately avoids mutating the lifted state's actionsByIds and computedStates properties, but instead creates a sanitized copy of them. This prevents the possibility of a sanitized action from changing the store state if, for example, its sanitized type coincided with a real action's type within the application.

Testing

In app.module.ts:

StoreDevtoolsModule.instrument({
  actionSanitizer: (action: Action, id: number) => {
    return { type: 'SANITIZED_ACTION' };
  },
  stateSanitizer: (state: any, index: number) => {
    return { ...state, extra: 'SANITIZED_STATE' };
  }
})

Open Chrome, confirm that it appears, while app and time travel seem to work fine.

@coveralls
Copy link

coveralls commented Feb 7, 2018

Coverage Status

Coverage increased (+0.1%) to 92.827% when pulling c6d6110 on kgkma:master into 0429276 on ngrx:master.

* Restructures the lifted state passed in to prepare for sending to the
* Redux Devtools Extension
*/
getSanitizedState(state: LiftedState, config: Partial<StoreDevtoolsConfig>) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pass the stateSanitizer as an argument instead of the config.

Copy link
Member

@brandonroberts brandonroberts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor change

@kgkma
Copy link
Contributor Author

kgkma commented Feb 12, 2018

@brandonroberts Thank you! Fixed as requested.

@brandonroberts brandonroberts merged commit a7de2a6 into ngrx:master Feb 12, 2018
@brandonroberts
Copy link
Member

Thanks!

@aboyton
Copy link

aboyton commented Feb 12, 2018

Any chance of a patch release so I can use this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants