Last active
September 19, 2017 01:08
-
-
Save dounan/bfb5c1218fa6ce2e858043b01bc7a0a5 to your computer and use it in GitHub Desktop.
Sentinel shallow copy gotcha
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const obj = {nested: {}}; | |
const wrappedObj = makeSentinel(obj); | |
// copiedObj is not a sentinel | |
const copiedObj = {...wrappedObj}; | |
copiedObj.value = "oops"; // mutation is NOT detected | |
// copiedObj.nested is a sentinel because it was copied from wrappedObj | |
copiedObj.nested.value = "oops"; // MUTATION DETECTED! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment