Created
December 5, 2019 14:08
-
-
Save gregdevs/4ec1b6c83d68846faf9bc6d075aeef5d to your computer and use it in GitHub Desktop.
Refactored NBC thoughts
This file contains hidden or 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
//******REFACTORED CODE*****/// | |
Going off ofmy memory of the test but I wanted to point out some improvements I would have made | |
// Instead of iterating and attaching event listeners on each path element, I would've wanted to go back and just have the click event attached to the parent and grab the target elem path from that instead. | |
const svgelem = document.querySelector('svg'); | |
svgelem.addEventListener('click', function(e){ | |
const state = e.target.getAttribute('data-state'), | |
votes = e.target.getAttribute('data-votes'), | |
party = e.target.getAttribute('data-party') | |
handleVotes(state, votes, party) | |
// remove if/else block here | |
}) | |
// Also, my if/else block with the vote count and class logic could be turned into a function passing in some params | |
//something like | |
function handleVotes(state, votes, party) { | |
do logic here | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment