non-enumerable (immutable) methods on Map/Set#1069
Conversation
when an immer object includes a Map/Set, the mutating methods are replaced with ones that prevent mutation outside of the procude function. to prevent cluttering the console when inspecting the Map/Set, these methods are set to non-enumerable. this behavior also matches that of the original methods that are replaced.
| if (isFrozen(obj) || isDraft(obj) || !isDraftable(obj)) return obj | ||
| if (getArchtype(obj) > 1 /* Map or Set */) { | ||
| obj.set = obj.add = obj.clear = obj.delete = dontMutateFrozenCollections as any | ||
| Object.defineProperties(obj, { |
There was a problem hiding this comment.
Looking good to me! As a nit optimisation, since the property map is constant, it could be lifted outside the function (usually that really doesn't matter, but with freeze potentially touching a gazillion of objects it might)
There was a problem hiding this comment.
Thanks! I'm waiting with sending the updated PR because the current state of the repo is failing some tests, both locally and using 'Open in Gitpod' (albeit a bit differently – locally tests/produce.ts, tests/draft.ts, and tests/redux.ts suits are failing, while in Gitpod the tests/immutable.ts is failing in addition to the other three).
Pull Request Test Coverage Report for Build 6139747876Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
|
🎉 This PR is included in version 10.1.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
when an immer object includes a Map/Set, the mutating methods are replaced with ones that prevent mutation outside of the produce function. to prevent cluttering the console when inspecting the Map/Set, these methods are set to non-enumerable. this behavior also matches that of the original methods that are replaced.