Code Monkey home page Code Monkey logo

Comments (4)

splincode avatar splincode commented on May 27, 2024

You can send pull request for fixed issue

from immer-adapter.

DympyDev avatar DympyDev commented on May 27, 2024

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 getState returns a draft and sets the frozenState variable, which is later on used to check if the changes need to be finalized in the setState implementation.

However, I wonder if this is intended behaviour.

Wouldn't it be better to have a getState and a separate getDraft method, or something like that.
This way, the default StateContext behaviour for the getState method wouldn't change when using immer (it would just return an immutable version of the state using immers castImmutable or something like that). And if you do want to manipulate the state, you can use the getDraft method, mutate away, and provide that to the setState method, where it will continue using the same behaviour as it does now.
In order to be able to use this "new" getDraft method, it might be wise for the apps to use the ImmutableStateContext interface, instead of the current StateContext interface.

I'm really interested in your thoughts about all this.
If you agree with them I'l happily create a PR attempting to do what I just described :)

from immer-adapter.

splincode avatar splincode commented on May 27, 2024

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 ngxs-labs/immer-adapter

 ctx.setState(produce((state) => {
     // your mutation
 }));

from immer-adapter.

pdemilly avatar pdemilly commented on May 27, 2024

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?

from immer-adapter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.