Do all the things like ++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatarSign Up
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple APILearn More
SortOfTested24915129dThey dont hang around in memory, you transform the old state to the new state, the previous state gets collected when it goes out of scope.
If that's not the case, you're doing it wrong.
SortOfTested24915129dThe current state cannot be mutated. You can take the current state, apply changes to a copy of the original data and receive a new state object, but you never have an object whose value you can alter.
The mechanisms of how you do that vary library to library and language to language, but the principle is the same.
But I think you're (@SortOfTested @Wisecrack) two different things.
The term structural sharing stems from joyful data structures...
In simple, not (fully) correct, binary search trees where only modified data between two states is added or inserted, rest is kept intact.
Reality is more complex. ;)
First off, let's talk immutability, immutablejs style:
The final result of an operation which transforms an immutable record is a new record. See example;
Immerjs' draft construct creates a tree of pending changes. These changes are instructions that will exist so long as they have not yet been applied. This is similar to immutable's withMutations.
It uses a strategy known as copy-on-write that will delay the actual creation of a new state copy until something actually modifies it. You keep a tree around as long as something is in a draft state. If that draft state is realized, the tree is finalized into a state and the copy is returned.
Personally I think immer is a shitshow, and immutablejs is poorly written. Both only exists because of Reactland's fascination with god object state machines. Just my opinion though.
It's not quite a trie. It's just an insertion order tree of proxies that only live so long as their mutations haven't been executed. You couldn't search down the tree to find context, it keeps the reference to a node in the caller and only crawls the parent axis. Branches are trimmed when refcount = 0 at intersectional nodes (no leaves).
kiki17670128dYes, they don’t hang around in memory. Imagine a linked list with two heads, v1 and v2. Perceived as two lists but they’re the same structure in memory.
Google “persistent data structures”
To me it simplifies it if you're dealing garbage jslang, but I also use rx code most of the time.
I find it preferable to have reliable messaging without the need to consider the case that something with a reference to the same object might have made changes that are incompatible with my algorithm.
Wisecrack4780128dall im asking is where the currentState actually must live..
its become obvious that the current state (less the base state) isnt stored on the base state, and it's not stored on nextState until the application ends, because otherwise you'd have a shit ton of variables of the flavor nextState1, nextState2, nextState3, etc, kicking around.
So you're telling me this is storing the curentState somewhere in immer itself or in a variable produced by immer?
kiki17670128d@junon you’re wrong and your dick is probably too small and you know it
Wisecrack4780127dcompletely off topic. i like this.
if its gonna be a couple might as well include SortOfTested and I to make it a foursome.
continue the insults. I find them exciting! 👉👈 👉👌👅😺🍆👂
I ran of ideas for lewd emojis.