non-mutative methods (e.g. splice) in withMutations should be documented to not work, or not possible
See original GitHub issueI’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:
- Created 9 years ago
- Comments:16 (2 by maintainers)
Top 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 >
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 Free
Top 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
@leebyron I’m also struggling to understand if/how deep operations like
setIn
operate insidewithMutations
, could you please clarify?What about
setIn
and the like?I just wrote some working code that uses
deleteIn
in awithMutations
scope. Confusing…Also I think the documentation should state that not supported methods fail silently.