Created
May 6, 2020 19:50
-
-
Save kyleshevlin/1e25b5193699994ac6fb082d457f7afe to your computer and use it in GitHub Desktop.
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
// This code solves a problem, but it doesn't tell me _what_ the problem is | |
// or _why_ I need to stop propagation. In the long run, someone | |
// will come across this code and have no idea why it's written this way | |
function handleItemSelection(event) { | |
event.stopPropagation() | |
selectItem(assetId) | |
} | |
// Here's my solution, one additional function, a small indirection that | |
// we can use to provide context to future people working on the code | |
function preventItemSelectionFromUpdatingAsset(event) { | |
event.stopPropagation() | |
} | |
function handleItemSelection(event) { | |
preventItemSelectionFromUpdatingAsset(event) | |
selectItem(assetId) | |
} | |
// What do you think? Could this be a useful pattern for you and your work? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment