Skip to content

Instantly share code, notes, and snippets.

@kyleshevlin
Created May 6, 2020 19:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kyleshevlin/1e25b5193699994ac6fb082d457f7afe to your computer and use it in GitHub Desktop.
Save kyleshevlin/1e25b5193699994ac6fb082d457f7afe to your computer and use it in GitHub Desktop.
// 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