New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Errors Not Thrown on Array.Push #25
Comments
But, you make a could point. Should methods that mutate throw errors or should the perform the action in an immutable way? |
Thanks for the information! I was not aware that a new implementation was being added for array methods that would otherwise update the array. I probably understood the goal of the library. I was looking for a library I could use during tests to make sure my Redux reducers didn't change the state or action argument passed in. But, you make a could point. Should methods that mutate throw errors or should the perform the action in an immutable way? Personally, I wouldn't use a library that changes the behavior of the JavaScript methods. I'd rather use the proper method (ES6 spread or .concat()) and avoid bad habits. What could be useful is error messages that explain why it's mutating the object. For example, calling .push on an "immued" object would throw an error that directs the user towards the correct solution such as concat. |
You make very interesting points. I think the original aim for the library was to mimic the Javascript api for objects and arrays, and just throw helpful errors when the user tries to mutate anything. In that spirit, all the methods were changed to be immutable if they were original mutable. I'm open to starting a new library that just throws errors on use of any mutation and leaves the methods as-is. Thoughts? |
Hey @scottcorgan. I think both are useful. I originally used I then found |
I sympathize with @andrewjmead's suggestion here. I actually have been searching for a minimal, well-supported way to guarantee immutability while using something completely functional (like Ramda) for modification. Thanks for putting this library together, and sharing it! |
Yes, I really am looking for a lib that just properly freezies everything, removes mutators and that's it. I don't want to be coupled to a immutability library because someone relies on using their mutator methods. |
First, thanks for the library. I love that it throws error so I can watch my tests fail.
I'm having an issue with the following snippet:
Trying to mutate an object runs as expected. The object does not get updated and an error is thrown.
Trying to mutate an array doesn't update the array, but it doesn't throw an error.
Is this expected behavior? Thanks!
The text was updated successfully, but these errors were encountered: