-
-
Notifications
You must be signed in to change notification settings - Fork 852
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
Patch for array.pop() replaces "length" #208
Comments
@aleclarson no meaning about it, both are semantically the same and length operations are probably unavoidable. For example, one could detect if only one item is removed, that a remove patch should be generated. But that might make If a patch is simple & small, I'm fine applying it; patch recording only guarantees that applying the same patches to the same state results in the same end state, not that it is the minimal or most optimal patch set :-). (Although the set is quite optimal actually in most cases) |
Closing for inactivity (and since PR has been closed?) cc: @aleclarson |
I don't think this was fixed?
|
Yeah, this should be fixed. We don't want to stray from JSON patches unless necessary. |
I've been using immer patches to synchronize a large JSON object between client (js) and server (elixir) - so that's great to hear. |
To fix this, rebasing and testing #210 is "up for grabs" to anyone who wants to contribute ❤️ |
@aleclarson Would love to contribute to the same. But would require a little bit of help |
@mweststrate What was the rationale behind diverging from RFC 6902 in the first place? |
@aleclarson Immer just intercepts writes to the object on all properties including length. If a So if |
@mweststrate Sorry, I was trying to ask why Immer doesn't follow RFC 6902 exactly, not why you diverged in this particular scenario. 😅 I assume it's because you didn't think it was worth the extra effort. :P |
Yeah, so the essence is: because we don't intercept _operations_, but
_mutations_ instead, so we don't know that a `length = 4` assignment
represents a pop or just a length increase until we would intercept
operations.
…On Wed, Jul 17, 2019 at 10:45 PM Alec Larson ***@***.***> wrote:
@mweststrate <https://github.com/mweststrate> Sorry, I was trying to ask
why Immer doesn't follow RFC 6902 exactly, not why you diverged in this
particular scenario. 😅 I assume it's because you didn't think it was
worth the extra effort. :P
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#208?email_source=notifications&email_token=AAN4NBGI7KIH2GGVZIA4T3DP76AG3A5CNFSM4FYZFPLKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD2GREFQ#issuecomment-512561686>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAN4NBHY3PAJ3BPG5ES6ZSLP76AG3ANCNFSM4FYZFPLA>
.
|
This is an inconvenience for me personally. I am following your blog post on how to distribute the state. In my use case, I need to convert the patches to database commands to persist them. Why?: By changing the draft inside the producer like so: Even if the state was exactly the same on the client as in the database, I would have to read all the items from the database to apply the length Because setting the length of the array to a lower length of the array deletes the elements inside, I propose catching this case and returning a PS. Awesome library! |
At this point in the spec it states that elements from an array should be a
Am I missing something or have I misunderstood? As far as I can tell, the spec specifies, that a remove should result in a remove and nothing else. |
🎉 This issue has been resolved in version 3.3.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Got this issue again after upgrading from v5 to v9 |
Let's assume
array = [ 0 ]
. Shouldarray.pop()
result in{ op: "remove", path: [ "0" ] }
instead of{ op: "replace", path: [ "length" ], value: 0 }
?I guess Immer is already "breaking" from the spec by making
path
an array and not/foo/bar
, but you could argue replacinglength
isn't friendly to non-JS environments.I assume the current behavior improves performance slightly.
https://codesandbox.io/s/0o1zx5226l
setUseProxies(true)
)setUseProxies(false)
)The text was updated successfully, but these errors were encountered: