Question on Baobab's immutability
See original GitHub issueI really must be missing something, maybe someone can clue me in.
Here is what I mean:
var a = new Baobab({ b: 1 })
var c = a.set('b', 2)
a.get('b') // I expected 1 but got 2!
c // I expected a reference to the new tree but was surprised to see 2
Am I wrong to think that Baobab should work like ImmutableJS in terms of preserving the tree on mutations on just returning an updated version?
ImmutableJS doesn’t have by default the excellent cursors and event system on data change like Baobab does and that’s why I turned to using Baobab - but was a bit surprised that data mutated on every update.
Issue Analytics
- State:
- Created 8 years ago
- Reactions:1
- Comments:11 (5 by maintainers)
Top Results From Across the Web
Issues · Yomguithereal/baobab - GitHub
Issues list ; Generic types for get, set, select, and apply; immutability for apply callback input. #512 opened on Oct 6, 2021 ;...
Read more >Plant a Baobab tree in your flux application - christianalfoni
Immutability can be a difficult concept to grasp, but a more important question to answer is; "why would you want to use it"?...
Read more >Immutable vs Immutable.js - ITNEXT
What does immutability stand for? The are just 2 rules that define “immutability”: – Don't mutate data, and if you have to –...
Read more >Pros and Cons of using immutability with React.js
Immutability is an idea. Nothing stops you from mutating objects directly. It needs programmer's discipline to implement those ideas. It can be ...
Read more >Newest 'baobab' Questions - Stack Overflow
Baobab is JavaScript persistent and optionally immutable data tree with cursors ... My main question is how do I 'subscribe' an Angular Component...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Immutability is all in the eye of the beholder. The underlying data is stored on very mutable RAM, so we know that fundamentally everything is mutable, it’s about the API that’s exposed to the user.
Consider this snippet, the first from the ImmutableJS README:
Or this one, the second example from the mori README:
The fact that these examples are so primary to the explanation of these two libraries should be a sign that they’re following the expected pattern for immutable data structures. That Baobab would be described as immutable and persistent, despite that fact that the API plainly isn’t, seems like a case of buzzword-compliance.
Let’s not water down the meaning of the terms.
👍 +1