Functions that accept and return objects should respect frozenness
See original GitHub issueFor example, with assoc:
var first = Object.freeze({a: 1, b: 2});
var second = R.assoc('c', 3, first);
console.log(Object.isFrozen(second)); // currently false
I believe that Ramda should maintain the frozenness of objects passed in. Discuss!
Issue Analytics
- State:
- Created 6 years ago
- Comments:12 (7 by maintainers)
Top Results From Across the Web
Object.freeze() - JavaScript - MDN Web Docs
freeze() returns the same object that was passed into the function. It does not create a frozen copy. A TypedArray or a DataView...
Read more >JavaScript Immutability – Frozen Objects in JS Explained with ...
You can freeze (make immutable) an object using the function Object.freeze(obj) . The object passed to the freeze method will become ...
Read more >JEP draft: Frozen Arrays (Preview) - OpenJDK
Although the JVM can sometimes do this under the covers, calling "freeze" on a mutable array will always return a different array.
Read more >The Frozenness of Pseudoclefts - University of Michigan
In order to understand in what ways pseudocleft sentences are restricted in their syntactic turnings, let us take a look at the number...
Read more >Ruby on Rails v6.0.0.beta1 Release - GitClear
For example these return an array of database config objects for the requested environment and a single database config object will be ...
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
@matthewp An ESLint rule might help you remain true to your FP principles. It looks like there are multiple options in this area, according to this google search.
That won’t help with libraries that mutate your objects, but it’s a start.
It might be interesting to have a companion library to Ramda that deep-freezes every object returned by any of the library’s functions. I wouldn’t use this in production, and I wouldn’t need it for myself, but it might be useful in a team scenario where not all team members can be trusted to avoid mutation to install the deep-freeze library as a development dependency and have a flag in your app that chooses which version of Ramda to load - deep-freeze for development and vanilla for production.
The excellent partial.lenses library has this behavior baked in. If I understand correctly, it deep freezes all objects returned by its methods if
process.env.NODE_ENV
is anything other than ‘production’. Everything’s frozen during development, but freezing is turned off in production.Most Ramda functions that take objects as arguments and return objects work with the objects’ own enumerable properties. There is no
isFrozen
own enumerable property on any object unless someone has added it explicitly (as you did tofirst
in your example).Think of
R.assoc
as being similar to JavaScript’s nativeObject.assign
. This native method, likeR.assoc
, only takes into account own enumerable properties.For example, you could naively recreate
R.assoc
based onObject.assign
:The object returned by this
assocNative
function will always be ‘unfrozen’, regardless of whether thetarget
object passed into it was frozen.See a more thorough example on Ramda’s REPL.
Also, you may be interested in taking a look at Ramda’s Gitter.