Re:Why I Like Using Maps (and WeakMaps) for Handling DOM Nodes
by taeric on Friday May 05, 2023 @08:12PM
(#35836674)
I'd say the big downside is that they don't support the general looking accessor that I'd wager way way way too many people will accidentally use. Myself definitely being one of them. Would have been better if they didn't "seem" to work with the wrong syntax, at least. But, alas, here we are.
Re:Why I Like Using Maps (and WeakMaps) for Handling DOM Nodes
by kevincox on Friday May 05, 2023 @08:50PM
(#35836883)
I'm typically using TypeScript so that is more or less a non-issue. But even then it seems like an easy thing to get used to.
Re:Why I Like Using Maps (and WeakMaps) for Handling DOM Nodes
by taeric on Friday May 05, 2023 @09:12PM
(#35837001)
Fair. And I didn't say it is a blocker. Just an easy footgun/downside. Is listed on the page linked, even.
Re:Why I Like Using Maps (and WeakMaps) for Handling DOM Nodes
by orange8 on Friday May 05, 2023 @09:31PM
(#35837103)
What is a "mapping" structure?
Re:Why I Like Using Maps (and WeakMaps) for Handling DOM Nodes
by RedShift1 on Saturday May 06, 2023 @03:29AM
(#35839069)
Key value, dictionary, ...
Re:Why I Like Using Maps (and WeakMaps) for Handling DOM Nodes
by panzerboiler on Saturday May 06, 2023 @03:22AM
(#35839036)
That fix is not really a fix. The thing being broken for general serialization is JSON.
Re:Why I Like Using Maps (and WeakMaps) for Handling DOM Nodes
by Kiro on Saturday May 06, 2023 @05:35AM
(#35839687)
And how do deserialize it back to a StringMap without manually doing so? Being able to run a JSON.stringify and then JSON.parse on your state tree seamlessly is important imo.
Re:Why I Like Using Maps (and WeakMaps) for Handling DOM Nodes
by programmarchy on Saturday May 06, 2023 @09:43AM
(#35841307)
I’ve been using io-ts for this and been very happy with it. [1] It’s similar to Swift’s Coding protocol in case you’re familiar.
I think MDN has a good comparison: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
The only real downside of maps is that they don't support JSON serialization. However you can fix this pretty easily by using a map with an overridden `toJSON` for serializable keys.