Code Monkey home page Code Monkey logo

Comments (7)

DanWahlin avatar DanWahlin commented on July 28, 2024

The reason that's done is due to change detection in libraries/frameworks. In Angular for example, without cloning the dispatched object the object reference wouldn't change so the UI wouldn't know to update without manual coding.

While the deepCloneState value could be passed into the dispatchState function, that could potentially break previous behavior in existing apps using the library so I'm hesitant to change that functionality right now.

from observable-store.

fifafu avatar fifafu commented on July 28, 2024

Maybe adding a global setting which wouldn't break existing behavior and needs to be enabled manually?

I'm using it a bit like redux and create new object references before passing them to setState. Change detection seems to work fine even without deep cloning.

I think deep cloning can also be problematic if performance is important for a specific use case.

from observable-store.

DanWahlin avatar DanWahlin commented on July 28, 2024

I don't want to add any additional properties at this point (trying to keep the API as basic as possible....which is proving challenging to do over time :-)). While I don't have the bandwidth to implement the change right now to stop cloning during a dispatch (when deepCloneState is false), let me think it over more. I suspect it won't impact many (if any) people but I'm always careful there.

If you end up having time to submit a PR that modifies that behavior to fit what you need I'm happy to consider that as well and run it through some scenarios I have when I get some time next week.

from observable-store.

fifafu avatar fifafu commented on July 28, 2024

Yep, I understand it's hard to keep things simple :-)

I'll also think about this a bit more and submit my suggestion as a merge request (I'm already using a patched version of the lib for our app).

from observable-store.

DanWahlin avatar DanWahlin commented on July 28, 2024

That sounds great. I'll definitely give that more consideration because I kind of feel that if someone set deep cloning to false then the dispatch shouldn't need to deep clone given that they knew what they were doing when they set it to false.

If you're able to submit a PR for what you've modified for your scenario I'll look it over more. Thanks!

from observable-store.

DanWahlin avatar DanWahlin commented on July 28, 2024

Hi @fifafu. You're probably tied up with other things I know but if you get a chance to submit a PR with the changes you wanted let me know. Happy to look at it and see the impact on existing usage.

from observable-store.

DanWahlin avatar DanWahlin commented on July 28, 2024

Going to close this for now but feel free to re-open if you get a chance to submit the code you mentioned.

from observable-store.

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.