-
-
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
bake in patchState immutability for simplicity #4245
Comments
There is already a similar issue, which is more about a compromise: #4030 We would have immutability on a type level and don't require immer. I created a PR for the prototype of the NgRx Signal Store. If there is interest, I could bring it up again. |
Left some context in that issue also, but we've discussed this issue over time https://github.com/ngrx/platform/issues?q=is%3Aissue+immer+is%3Aclosed+ |
The immerPatchState(store, (state) => {
state.todos.push('foo');
}); Closing this issue in favor of timdeschryver/ngrx-immer#21 |
I'm using this issue to promote timdeschryver/ngrx-immer#21 |
@timdeschryver, I would take that one. So if there's a waiting list out there, please add me. |
@rainerhahnekamp @markostanimirovic @timdeschryver FWIW I have just implemented (or rather, bridged) it here: https://github.com/ducin/sygnalyze. Although it very slightly overlaps with |
@ducin, good, so I understand that I can still extend |
yeah, I think so |
Which @ngrx/* package(s) are relevant/related to the feature request?
signals
Information
The proposal is to use
immer
ormutative
in order to simplify immutable operations maintenance for developers.Motivation
Signals require immutable updates. For nested structures, writing immutable code by hand is going to be cumbersome for devs. This proposal aims to remove this incovenience.
Example
the "hidden" immutability would be baked in
patchState
.BEFORE:
AFTER:
and this is how
mutative
/immer
normally work:Context
In react ecosystem people have to apply immutable data updates. That was one of the many painpoints with original
redux
, which introduced the need for quite a lot of boilerplate. The need for immutability in reducers was one of the factors that made redux quite unpopular within react community in last years. Later, @markerikson did a great job by introducingredux-toolkit
(opinionated, 50%+ less code to do typical redux in apps), which has reduced the boilerplate significantly. One of the great improvements was introducingimmer
as a hard dependency. All redux-toolkit users I know are super happy with how immer removes the need for spreading the objects over and over again.Drawbacks
The only downside I'm seeing is potentially the bundle size which currently is super small.
Describe any alternatives/workarounds you're currently using
Let people write spread objects as they are doing now.
I would be willing to submit a PR to fix this issue
OF COURSE (:
The text was updated successfully, but these errors were encountered: