-
Notifications
You must be signed in to change notification settings - Fork 2
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
Improve deepFreeze function a bit #1
base: master
Are you sure you want to change the base?
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