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.

non-mutative methods (e.g. splice) in withMutations should be documented to not work, or not possible

See original GitHub issue

I’m not sure if this is a bug, or if I’m doing something wrong. But when I try to splice one item into a List inside a withMutations block, I’m getting an empty list as a result. For example:

var list = Immutable.fromJS([1,2,3]);
list.splice(1,0,10).toJS() // List [1, 10, 2, 3]

But, if I try to do the same thing, but using withMutations, it returns an empty list:

var list = Immutable.fromJS([1,2,3]);
list.withMutations(function(l){
  l.splice(1,0,10);
}).toJS() //List []

I’ve also tried this, but it gives the same result.

var list = Immutable.fromJS([1,2,3]);
list.withMutations(function(s){
  s.updateIn([], function(l){return s.splice(1,0,10); });
}).toJS() //List []

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:16 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
thiemancommented, May 24, 2016

@leebyron I’m also struggling to understand if/how deep operations like setIn operate inside withMutations, could you please clarify?

0reactions
xMartincommented, Jan 7, 2016

What about setIn and the like?

I just wrote some working code that uses deleteIn in a withMutations scope. Confusing…

Also I think the documentation should state that not supported methods fail silently.

Read more comments on GitHub >

github_iconTop Results From Across the Web

non-mutative methods (e.g. splice) in withMutations should be ...
non-mutative methods (e.g. splice) in withMutations should be documented to not work, or not possible #196.
Read more >
When should I use `withMutations` on a map in Immutable.js?
You should use withMutations when you want to group several changes on an object. Because each change creates a clone, several changes in...
Read more >
Stack - Immutable.js
Note: Not all methods can be used on a mutable collection or within withMutations ! Check the documentation for each method to see...
Read more >
Remove an Array Element Without Mutation - Jake Trent
Mutation means that the original array is changed in place. A common way to do this is with splice . With splice ,...
Read more >
immutable.js-flow-fix - npm
Persistent data presents a mutative API which does not update the ... important to use the Immutable.is() function or .equals() method to ...
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