Created
December 11, 2019 20:09
-
-
Save kyleshevlin/f7519f17175b66a5d4d24b8e82b067db to your computer and use it in GitHub Desktop.
enumerateDontBooleanate.js
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 isLoading = true // Great, we know we know something is loading | |
const isLoading = false // We only know we're not loading, ANYTHING ELSE IS POSSIBLE | |
// In symbolic logic, this is referred to as a _modus tollens_ | |
// the negation of an assertion only tells us that _that_ particular thing | |
// in the universe is negated, it conveys _no_ logical information about anything else | |
// Ex. If I have a Mtn Dew in front of me, I will drink it. | |
// I do _not_ have a Mtn Dew in front of me, therefore I can't assert anything | |
// about anything I am doing other than _not_ drinking a Mtn Dew | |
// It is better to enumerate states than to boolean-ate states (Yes, I may have made that up) | |
const STATES = { idle, loading, success, failure } | |
// Now there is no confusion regarding what it means when I check what state I'm in | |
if (currentState === STATES.loading) { doSomething() } | |
// Also, this has the benefit of being able to respond conditionally to states with other enums | |
const TEXT_RESPONSES = { | |
idle: `I'm chilling`, | |
loading: 'Loading...', | |
success: 'Huzzah!', | |
failure: 'Womp, womp...' | |
} | |
const currentState = STATES.success | |
const displayText = TEXT_RESPONSES[currentState] // Huzzah! | |
// Enjoy! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment