Show HN: An isomorphic, configurable JavaScript utility for object deep cloning
github.com
github.com
Is the word being used in some other sense?
That being said, I'm a little baffled after reading that article. I suppose the thinking was that the client and server are isomorphic to each other if they're running the same code. As someone who also has a mathematical background I don't think it's very elegant...but it's obviously caught on and it's creative, so I can dig it.
I don’t think mathematics should get a monopoly on this one. Though it can probably keep “isomorphism” to itself, since “morphism” is as far as I know a made up math term.
The term 'isomorphic' refers to the output, as in being able to render the same UI / application on the server and on the client.
It’d be easy to be active and not come across it though. Most of the JavaScript world maintains a clear client/server separation. In my experience most production apps can’t share code between client and server. It’s either written and packaged for one or the other.
Thanks
EDIT: I said assign method earlier, I meant create. The assign method is the pre-ES6 way of creating object instances. Object.create() is used to inherit prototypes. That’s such a common mix-up that I’m embarrassed I didn’t catch it.
(Of course I can and do use ES6 when coding for other people, I write to whatever standard is established in a codebase.)
In almost a decade of using Clojure, I've never seen persistent data structures become the bottleneck. The difference in cost is O(1) for in place mutation vs O(log 32 n) for revisioning. Note that the large exponent means the tree ends up being very flat, so updates end up being quite cheap in practice. Most times when I do something to a persistent data structure, I only change a small portion of the overall data structure. In fact, I think it's quite rare that you'd end up cloning the whole thing.
Personally, I view mutability as an optimization, and I think it should be used in cases where you actually need the performance beyond what persistent data structures can offer. My experience is that such cases are far and few between.
From user perspective, you're effectively making a copy each time you make a change, but you're not paying the price of a full copy. Instead, the cost of updates tends to be o( log n) vs o(1), which turns out to be fast enough for vast majority of cases. You can read about this in more detail here: https://en.wikipedia.org/wiki/Persistent_data_structure
JavaScript has a number of libraries that implement these data structures, underscore.js and immutable.js are examples. However, these libraries still require a lot of programmer discipline to use. For example, nothing stops you from putting a mutable object into an immutable data structure. At that point all bets are off.
There are also languages that are built around the idea of immutability. For example, I work with ClojureScript, and all data there is immutable by default. Data structure syntax in ClojureScript is actually quite similar to JSON, and it makes it easy to move between the two.
edit: seems like you updated as i posted. i’m just trying to understand how you do this without using an object. you mention use of a map, but that is also an object. also, by copying a map i still access the original values, which is specifically what this article is implemented to avoid? i may be over my head here, i’m just trying to understand the “correct” way of doing this in javascript.
IMHO the concept of "deep clone" is a design pattern and a potential language improvement idea. An example is "How does this deep clone handle external items, or transient items, or circular items?" Your project shows (correctly IMHO) that there many be many choices, and also reasonable defaults.