News for hackers. Stuff that matters.
Re:Immutable.js: An Introduction with examples written for h... by Illniyar on Sunday November 27, 2016 @04:38PM (#13051699)
I find seamless-immutable to be much much better. It mostly follows the standard javascript api, and throws an error when you use a mutable action.

Makes it very simple to use it anywhere you'd use a plain array or object, rather then always having to use immutable.js's api.

Re:Immutable.js: An Introduction with examples written for h... by undershirt on Sunday November 27, 2016 @04:44PM (#13051732)
seamless doesn't implement the "persistent" part of immutable persistent data structures. The persistent part means you can create a cheap modification of the data structure, with structural sharing between "copies".
Re:Immutable.js: An Introduction with examples written for h... by Illniyar on Sunday November 27, 2016 @05:56PM (#13052110)
The main benefit I derive from immutability in js is identity comparison (I.E. react's shouldComponentUpdate), I don't find the small performance hit of cloning to make a difference.
Re:Immutable.js: An Introduction with examples written for h... by Illniyar on Sunday November 27, 2016 @05:49PM (#13052083)
What do you mean? I'm pretty sure it only clones the minimal necessary.

I.E. if I have {a:{aa:"1"},b:"cc"} and I change b, then {aa:"1"} will not be deep copied.

Are you talking about something like keeping a reference to the parent and sending lookups up the chain (with a prototype or some such?)

Re:Immutable.js: An Introduction with examples written for h... by Tarean on Monday November 28, 2016 @08:31AM (#13055242)
The simplest example would be a persistent list. Think you first create a list [c,d,e]. You can safely share references to that. Then you attach a to one version and b to another:

    a \
       c-d-e
    b /
The memory for the original list is still shared! You can generalize that to trees and use that to implement, say, persistent hashmaps that can share data.

This is also awesome for parallelization where you want to share data but don't need synchronization!

Re:Immutable.js: An Introduction with examples written for h... by moon_priestess on Sunday November 27, 2016 @10:41PM (#13053254)
The person you are replying to is talking about things like maps implemented with persistent trees. Updating a value in such a map generally only involves copying O(log N) nodes in the tree: It's not necessary to shallow copy the entire tree itself.
Re:Immutable.js: An Introduction with examples written for h... by Illniyar on Monday November 28, 2016 @12:04AM (#13053522)
And immutable.jsdoes that?
Re:Immutable.js: An Introduction with examples written for h... by undershirt on Monday November 28, 2016 @08:34AM (#13055259)
Oops, didn't realize that seamless does its own shallow copying strategy with `merge`, `set`, `setIn`. I can't speak to how this compares to persistent data structures implemented by immutable.js, clojure, elm, etc. But it looks like the seamless author said the following about it:

> Persistent data structures are different, as their performance improvements are passive. Although seamless-immutable does not (and cannot, while maintaining its backwards compatibility with vanilla JS collections) use things like VLists under the hood, its cloning functions—such as merge—only bother to make shallow copies, as shallow and deep copies of immutable values are equivalent. In practice, this simple passive optimization has been sufficient; we have yet to encounter a performance problem that Bagwell-style persistent data structures would have solved.

from: http://tech.noredink.com/post/107617838018/switching-from-im...

Re:Immutable.js: An Introduction with examples written for h... by Waterluvian on Sunday November 27, 2016 @05:07PM (#13051874)
Aye. I found its interface to be simpler but it quickly became clear that it was fundamentally useless since I lost the performance gains of partial mutations that left unmutated parts of the structure with the same reference.