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
- Add more docs around what is and isnt safe to use in withMutations Fixes #890 Fixes #196 Fixes #401 Fixes #228 — committed to immutable-js/immutable-js by leebyron 7 years ago
- Add more docs around what is and isnt safe to use in withMutations Fixes #890 Fixes #196 Fixes #401 Fixes #228 — committed to immutable-js/immutable-js by leebyron 7 years ago
- Add more docs around what is and isnt safe to use in withMutations (#1110) Fixes #890 Fixes #196 Fixes #401 Fixes #228 — committed to immutable-js/immutable-js by leebyron 7 years ago
- Similar factories should be equals (#196) Co-authored-by: Nathan Bierema <nbierema@gmail.com> — committed to Methuselah96/immutable-js by jdeniau 4 years ago
@leebyron I’m also struggling to understand if/how deep operations like
setIn
operate insidewithMutations
, could you please clarify?