-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Add Mutation and Serialization Checks into Store #857
Comments
Here is a potentially useful addition to the idea. Perhaps in this default development mode, in addition to freezing the objects, it could round-trip them through JSON at each pass through Store. This would expose problems with non-serializable data much earlier in the application development lifecycle, which I think would help some developers quite a lot. I've seen various people/teams, both online and in our consulting and training work, where they build machinery around Store that both relies on mutable data and relies on data that cannot be serialized... and then realize that they either have to give up forever on the things that those limitations would enable, or rethink work that they already worked quite hard on. |
@kylecordes I love it. |
+1 |
@kylecordes I'm not sure, I fully follow the
How would you suggest round-tripping handle If anything, IMHO, such round-trip should be optional even in |
@tomwanzek Yes, exactly! By round tripping the data through JSON, developers would have to make a choice:
I certainly don't suggest that in production the data go through such a thing, as it is pointlessly slow and wastes memory. But I am urging this to be the default during initial development, because we have tried the opposite default: Up through now, the default has been no default tooling or settings which would guide developers to use serializable, immutable state. And what I see out there in the wild, is that most projects that have picked up Store (or the Redux architecture in general) do not have these desirable attributes. By the time folks understand the architecture enough to want those things, they already have a bunch of legacy code written without that understanding. |
@kylecordes I guess, one of my main concerns is that the implementation of the underlying serialization API does not foreclose critical use cases. I.e. in one of my critical use cases I have entities, which have an outer skeleton structure which is known at design time, but the schemata which govern some of their nested properties, are only known at run time. These schemata themselves are entities of the store in their own right. As ensuring that ngrx serialization does not shut out such a use case, I will add a slightly less abstract comment to the related issue #856. |
Is this up for grabs? |
@tdeschryver I have a prototype implementation: https://github.com/ngrx/platform/tree/feat/serialization-and-mutation-checks I realized that we will need a few enhancements made to Store before we can land this:
All three of these are prototyped in that branch. If you want to help carry it over the finish line you are more than welcome to do so. |
I should also point out that the API prototyped in the branch looks like this: StoreModule.forRoot(reducers, {
dangerouslyDisableRuntimeChecks: [
RuntimeChecks.Immutability,
RuntimeChecks.Serializability,
],
}), but after discussing it with @brandonroberts we decided to go with a more TypeScript-inspired API: StoreModule.forRoot(reducers, {
runtimeOptions: {
strictImmutabilityChecks: false,
strictSerializabilityChecks: false,
}
}), |
I gave it a quick glance and its looking good already 👌 Maybe some food for thought (because I was fiddling with this feature to get more familiar with the code base and these are the main differences):
|
Just a note here to bring this up to the surface, the It's just important to keep custom serialization and store dev tool replacer configuration open for customization, but I don't think there's any talk about removing that 😄 |
If we choose to implement #856 we should consider adding mutation checks directly into store. Think ngrx-state-freeze but built-in and it also checks if state can be serialized.
Considerations:
The text was updated successfully, but these errors were encountered: