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

Option to applyPatches mutatively (without cloning object) #110

Closed
Ctrlmonster opened this issue Feb 8, 2024 · 3 comments
Closed

Option to applyPatches mutatively (without cloning object) #110

Ctrlmonster opened this issue Feb 8, 2024 · 3 comments

Comments

@Ctrlmonster
Copy link

Hey, thanks for making this awesome library!

I've been looking for a more performance minded alternative to immer, as I'm developing a latency sensitive browser game and want to send game-state patches over the wire, so structura seems like a perfect fit :)

Now my question/problem is whether it's possible to apply patches in a way that manipulates an existing object and skips the cloning step. Reason for needing this is that my object on the client side isn't just an object but only provides an object-like interface with custom setters that wire the data to some other place and I want to avoid re-creating this complex interface every time I receive patches.

// something like
const res = applyPatchesMutatively(myObject, patches);
expect(res === myObject);

Cheers 🙌

@Ctrlmonster Ctrlmonster changed the title Option to applyPatches mutatively Option to applyPatches mutatively (without cloning object) Feb 8, 2024
@giusepperaso
Copy link
Owner

Hi @Ctrlmonster, thanks to you for the feedback!

I've implemented your suggestion, it is now possible to import and call applyPatchesMutatively

Just upgrade to version 0.12.0, be sure that auto freeze is disabled and do not return inside the producer

This is very new, so if you encounter any problem let me know!

@Ctrlmonster
Copy link
Author

That was fast! @giusepperaso

Works like a charm for me, thank you so much!
I'll report back if I encounter any problems.

One small note, in the docs it says Sometimes you may want to apply patches to an object without mutating it., the last part should probably be without cloning it :)

@giusepperaso
Copy link
Owner

giusepperaso commented Feb 9, 2024

glad to know it works for you
thanks for noticing the typo, I've corrected it

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

No branches or pull requests

2 participants