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(Store): runtime checks #1613

Merged
merged 2 commits into from
Apr 1, 2019
Merged

feat(Store): runtime checks #1613

merged 2 commits into from
Apr 1, 2019

Conversation

timdeschryver
Copy link
Member

@timdeschryver timdeschryver commented Mar 9, 2019

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[x] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Other... Please describe:

What is the current behavior?

Closes #857

What is the new behavior?

  • State serialization checks

  • Action serialization checks

  • Mutation checks

  • Remove ngrx-store-freeze ?

  • Remove non-serializable properties on the router ?

Does this PR introduce a breaking change?

[x] Yes
[ ] No

BREAKING CHANGE:

The META_REDUCERS token has been renamed to USER_PROVIDED_META_REDUCERS
The META_REDUCERS token has become a multi token and can be used by
library authors

Other information

Based of feat/serialization-and-mutation-checks

This PR also affects #1539

this.next(state);
scannedActions.next(action);
},
error: err => this.error(err),
Copy link
Member Author

@timdeschryver timdeschryver Mar 9, 2019

Choose a reason for hiding this comment

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

This change was needed in order for me to test the case with an invalid next state.

@ngrxbot
Copy link
Collaborator

ngrxbot commented Mar 9, 2019

Preview docs changes for f4b02ae at https://previews.ngrx.io/pr1613-f4b02ae/

@ngrxbot
Copy link
Collaborator

ngrxbot commented Mar 9, 2019

Preview docs changes for 0f52c54 at https://previews.ngrx.io/pr1613-0f52c54/

@ngrxbot
Copy link
Collaborator

ngrxbot commented Mar 9, 2019

Preview docs changes for 8e3eaf8 at https://previews.ngrx.io/pr1613-8e3eaf8/

@ngrxbot
Copy link
Collaborator

ngrxbot commented Mar 10, 2019

Preview docs changes for 38e9cc1 at https://previews.ngrx.io/pr1613-38e9cc1/

@timdeschryver
Copy link
Member Author

Is this the API we had in mind?

@brandonroberts
Copy link
Member

Yes, I like the API. A few thoughts:

  • I wonder how much router-store would be impacted from removing paramMap and queryParamMap?
  • I think this has the potential to uncover many accidental mutations in peoples apps (break them).
  • What's the migration strategy for those overriding the META_REDUCERS token today?

@timdeschryver
Copy link
Member Author

timdeschryver commented Mar 12, 2019

I wonder how much router-store would be impacted from removing paramMap and queryParamMap?

We still have params and queryParams which is the same object (?) but without some getters or util functions.

I think this has the potential to uncover many accidental mutations in peoples apps (break them).

What about making these checks opt-in v8 and log a warning on start up (in dev) that these checks will be the default in v9 or v8.x?

What's the migration strategy for those overriding the META_REDUCERS token today?

Is it correct that if we would flatten out the meta reducers inside the concatMetaReducers function this shouldn't be a problem? The only issue would be that these reducers would be registered as an internal or library meta-reducer
To test this out I will create a test 😄

@timdeschryver
Copy link
Member Author

See fcd21bb, I lied. The user also has to add multi: true.

But now that I'm thinking about it, the user has to change the token from META_REDUCERS to USER_PROVIDED_META_REDUCERS.

@ngrxbot
Copy link
Collaborator

ngrxbot commented Mar 12, 2019

Preview docs changes for fcd21bb at https://previews.ngrx.io/pr1613-fcd21bb/

@timdeschryver
Copy link
Member Author

For an easy transition we could provide a linter and possibly add it to the migration script?
Something like https://github.com/timdeschryver/tslint-playground/blob/master/src/rules/noMetaReducersRule.ts.

@ngrxbot
Copy link
Collaborator

ngrxbot commented Mar 13, 2019

Preview docs changes for 89a9b21 at https://previews.ngrx.io/pr1613-89a9b21/

@brandonroberts
Copy link
Member

I think we should do a separate PR to remove the non-serializable parts (paramMap, queryParamMap) from router-store so we aren't breaking too many things here.

@@ -6,6 +6,7 @@ export {
MetaReducer,
Selector,
SelectorWithProps,
RuntimeChecks,
Copy link
Member

Choose a reason for hiding this comment

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

These don't need to be exported publicly except for USER_PROVIDED_META_REDUCERS

metaReducers,
runtimeChecks: {
strictStateSerializabilityChecks: false,
strictActionSerializabilityChecks: false,
Copy link
Member

Choose a reason for hiding this comment

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

Where are we mutating actions? We should clean this up.

@ngrxbot
Copy link
Collaborator

ngrxbot commented Mar 16, 2019

Preview docs changes for 60ce1c9 at https://previews.ngrx.io/pr1613-60ce1c9/

@timdeschryver timdeschryver marked this pull request as ready for review March 16, 2019 17:15
@ngrxbot
Copy link
Collaborator

ngrxbot commented Mar 16, 2019

Preview docs changes for 0bd736a at https://previews.ngrx.io/pr1613-0bd736a/

@ngrxbot
Copy link
Collaborator

ngrxbot commented Mar 21, 2019

Preview docs changes for b553983 at https://previews.ngrx.io/pr1613-b553983/

@@ -39,3 +39,9 @@ export type SelectorWithProps<State, Props, Result> = (
state: State,
props: Props
) => Result;

export interface RuntimeChecks {
strictStateSerializabilityChecks: boolean;
Copy link
Member

Choose a reason for hiding this comment

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

We are already calling these RuntimeChecks, so we can remove Checks from the properties themselves.

@@ -29,7 +29,14 @@ export function createTestModule(
TestBed.configureTestingModule({
declarations: [AppCmp, SimpleCmp],
imports: [
StoreModule.forRoot(opts.reducers),
StoreModule.forRoot(opts.reducers, {
Copy link
Member

Choose a reason for hiding this comment

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

Remove this as its opt-in

if (isDevMode()) {
if (runtimeChecks === undefined) {
console.warn(
'@ngrx/store: we added immutability and serializability runtime checks in @ngrx/store.\n' +
Copy link
Member

Choose a reason for hiding this comment

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

I think we should keep this message short and add information about the checks to a page we link to. Another idea is to make this a comment for the RootStoreConfig so it shows up in their IDE and makes the console less noisy.

Copy link
Member Author

@timdeschryver timdeschryver Mar 21, 2019

Choose a reason for hiding this comment

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

Yea, you're right 😅 the link to a page is a good idea 👍
My intention was to log it so it will certainly be visible, but this can quickly become annoying. It will also log out the messages in people's tests... On the other hand I'm afraid this change will be unnoticed by teams if don't log it and only add a comment on RootStoreConfig.

The consolw.warn can be "disabled" by providing a config, this can just be an empty object.

What do you think of logging:

@ngrx/store: runtime checks are currently opt-in but will be the default in the next major version, see -link- for more information.

The link can point to the changelog, or the migration page on ngrx.io

Copy link
Member

Choose a reason for hiding this comment

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

👍

@ngrxbot
Copy link
Collaborator

ngrxbot commented Mar 21, 2019

Preview docs changes for 74b5ce7 at https://previews.ngrx.io/pr1613-74b5ce7/

@ngrxbot
Copy link
Collaborator

ngrxbot commented Mar 21, 2019

Preview docs changes for 9d66646 at https://previews.ngrx.io/pr1613-9d66646/

@ngrxbot
Copy link
Collaborator

ngrxbot commented Mar 24, 2019

Preview docs changes for 9242ce3 at https://previews.ngrx.io/pr1613-9242ce3/

1 similar comment
@ngrxbot
Copy link
Collaborator

ngrxbot commented Mar 24, 2019

Preview docs changes for 9242ce3 at https://previews.ngrx.io/pr1613-9242ce3/

@brandonroberts
Copy link
Member

@timdeschryver will you rebase so we can land this?

@brandonroberts
Copy link
Member

brandonroberts commented Mar 31, 2019

Does this need to land as a rebase? Are there any breaking change commits? If so, the other commit messages need to be cleaned up.

This includes serialization checks and mutation checks

BREAKING CHANGE:

The META_REDUCERS token has been renamed to USER_PROVIDED_META_REDUCERS
The META_REDUCERS token has become a multi token and can be used by
library authors
@timdeschryver
Copy link
Member Author

I've rebased and added a BREAKING CHANGE comment

@ngrxbot
Copy link
Collaborator

ngrxbot commented Apr 1, 2019

Preview docs changes for 218a1a4 at https://previews.ngrx.io/pr1613-218a1a4/

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

Successfully merging this pull request may close these issues.

Add Mutation and Serialization Checks into Store
3 participants