2

Reactive state tracking in JS frontend frameworks is just ridiculous

This is a language that encourages you to create huge trees of objects but from what I can tell most frameworks have real trouble detecting any change more complex than a direct assignment

Am I missing something? I have a reactive list of objects of which fields get updated. I have no idea how to make that trigger UI updates.... This is just torture

Comments
  • 3
    Sad that this is every other reaction from the "this is something new, I refuse to try to understand" devs/people...

    Yes, js has its limitations, but you wouldn't track every prop on every deeply nested object in any language unless completely necessary. There are ways to have the reactivity trigger, usually by replacing the object completely. But impossible to say without knowing exactly what you're doing with what framework.
  • 1
    @ScriptCoded How is this sad and how am I a bad dev because of it? I had a bad experience from dumb APIs

    I'm not here to shit on js (i actually like js now) but wtf

    "just recreate the entire object" okay sure, is there an easy way to do that? Not that I know. Apart from the fact that incrementing a single number now turned into "just deep copy an entire object tree"
  • 1
    @12bitfloat Never said you were a bad dev, never would.

    Usually you can just spread. So something like this

    x = {
    ...x,
    y: x.y + 1
    }
  • 1
    @ScriptCoded That doesn't do a deep copy though

    I guess my problem is somewhat atypical because I'm trying to update a field of an object in an reactive array from an event listener (which doesn't know which entry in the array is "me")

    I don't know. Maybe I should just finally switch to react, but it still doesn't feel right. Surely there has to be a better answer than "deep copy your entire application state" from an architectural perspective
  • 1
    If you really, REALLY need to track changes in deeply nested objects, look into proxies. You can recursively create proxy trees.

    It's shit, really inefficient, but if you really gotta "deeply" track an object, yeah.

    But if you're at this point, you may wanna rethink your architecture.
  • 1
    In a non garbage language you'd simply use value types :)
  • 0
    You can also do it with a reducer that assembles your global application state from its parts.
  • 1
    @12bitfloat you are not really deep-copying anything iirc. You do from the programmer pov, but in memory things are handled smartly.

    I don't understand what the problem is. You have an object change you're trying to react to, but it doesn't trigger the change? Sounds like an issue with your algorithm.
Add Comment