Improve deepFreeze function a bit - #1
Conversation
|
Also, I believe freezing functions requires some more care as you cannot freeze Not freezing null is a must though, it'll throw in browsers/phantomjs if you don't. It's unfortunate that https://github.com/substack/deep-freeze and https://github.com/jsdf/deep-freeze are buggy. If they weren't, we wouldn't need to roll our own Maybe it'd be worth pulling out a common implementation for just the freeze that updeep and icedam can depend on? |
|
As an aside, @winkler1, I noticed you used |
|
@aaronjensen Adding the null check and an explicit test, thanks. The Redux devtools make a point of saying to use serializable data structures for its time travel abilities. Will beef up the tests for null and function. A common Really want to ensure that in production this is a 3-line no-op, no dependencies... |
|
@aaronjensen re:enumerable - now that you mention it... non-enumerable props are stripped by JSON.stringify cloning, so Object.keys would work just as well. I'll add a test to make this explicit: |
|
👍 wrt to dev vs prod, a couple things: You might consider looking for Also, for this lib it'd remove a lot of conditionals and may make the code a bit easier if you did something like: if (process.env.NODE_ENV === 'production') {
module.exports = function makeFreezer() {
function(obj) { return obj; }
}
} else {
// existing code
module.exports = function...
} |
|
Actually, I went to do this on updeep and found that everything in |


Check for null properties and freeze functions as well