question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question on Baobab's immutability

See original GitHub issue

I 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:open
  • Created 8 years ago
  • Reactions:1
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
couchandcommented, Feb 23, 2016

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:

var Immutable = require('immutable');
var map1 = Immutable.Map({a:1, b:2, c:3});
var map2 = map1.set('b', 50);
map1.get('b'); // 2
map2.get('b'); // 50

Or this one, the second example from the mori README:

var v1 = mori.vector(1,2,3);
var v2 = mori.conj(v1, 4);
v1.toString(); // => '[1 2 3]'
v2.toString(); // => '[1 2 3 4]'

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.

0reactions
dumconstantincommented, Feb 24, 2016

👍 +1

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found