Best way to mutate immutables?
See original GitHub issueImmutableJS sucked becauase of its overly verbose way to access data. But it had nice mutators.
If I’m using it properly, seamless-immutable relies on what methods return a new value, so we’re missing a lot of how to mutate data. Is there a cleaner way to push a new element onto an array? Currently I’m doing something like this:
let updatedArray = this.state.arr.asMutable();
updatedArray.push(newElement);
this.setState({arr: new Immutable(updatedArray)});
Issue Analytics
- State:
- Created 8 years ago
- Reactions:1
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Immutability in React: Should you mutate objects?
Over 200k developers use LogRocket to create better digital experiences ... The most simple solution is to use immutable objects. If the object ......
Read more >Reading 9: Mutability & Immutability
Since String is immutable, once created, a String object always has the same value. ... Notice that this method does its job by...
Read more >How to Mutate Data in a System Designed for Immutable ...
In our Field Guide series, we share challenges and successes we've encountered while exploring uncharted territory.
Read more >Convenient Way to Mutate Immutable Objects
method to clone a new immutable object with a new property value? The mutate function above demonstrated how to mutate an immutable object ......
Read more >Immutable Update Patterns
Structuring Reducers > Immutable Update Patterns: How to correctly ... These lead to accidental direct mutation, and should be avoided.
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
That’s true, that
delete
would be useful, however the name doesn’t seem safe - it can easily collide with reserved keyword. I would actually call itwithout
.In one of my projects I came up with this helper function:
Then you can remove 3rd item by calling:
I can make a PR to use it as a method of immutable array. What do you think, @rtfeldman ?
As for the
push
- is there anything wrong withconcat
?Did this ever get implemented or discussed?