-
Notifications
You must be signed in to change notification settings - Fork 10
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
getState within @ImmutableContext() returns a draft #483
Comments
You can send pull request for fixed issue |
I understand, and I would love to do that, but some guidance would be appreciated as for why the getState returns a draft right now. From what I can see, the However, I wonder if this is intended behaviour. Wouldn't it be better to have a I'm really interested in your thoughts about all this. |
To be honest, I don’t remember why I did this)) this project was experimental and I decided that using decorators was bad and unreadable I recommended use native produce from immer instead ctx.setState(produce((state) => {
// your mutation
})); |
I have been using extensively produce(ctx, draft => { ... }) in my code and it works great but have been declared deprecated in recent built. Is it replaced by ctx.setState(produce(state) => { }); Any pitfall I should be aware when changing it? |
So in our application we use this immer-adapter to help make our state immutable.
However, we recently ran into an issue where our production build breaks our apps.
It seems that everything is a lot stricter in production builds than in development build, which pointed us to a bunch of errors when using the getState method.
The getState method returns an immer draft, instead of, what we expected, a frozen instance of our state.
As you can see at this line:
https://github.com/ngxs-labs/immer-adapter/blob/master/src/lib/core/immer-adapter/common/immutable-state-context.ts#L23
It just creates a draft, casts it to the provided interface, calls it frozen and then returns it.
We tried to recreate this issue in an isolated project, and the results were the same.
So given an action like this, that finds an object (Dossier) in an array (dossiers) from the state, based on the dossierNumber:
We will receive an output like this, and the state would not have been modified (as the found object is nog present in the dossiers list):
However, we would expect something like this (along with the found object to be removed from the dossiers list):
If a working example is required, please do tell and I will try to provide a stack blitz as soon as possible.
The text was updated successfully, but these errors were encountered: