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

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 []

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 16 (2 by maintainers)

Commits related to this issue

Most upvoted comments

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