All examples from a 20k LOC Elm code base that has been in production for 2 years now.
-
-
Save klazuka/fdd18790ce50ee291a1a210c63ef48f7 to your computer and use it in GitHub Desktop.
comparing single line if-then-else for elm-format
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
{- | |
Examples which I think are improved by single-line formatting of `if-then-else` | |
-} | |
-- status quo | |
viewSave { isSaving } = | |
div [] | |
[ button | |
[ onClick Save, disabled isSaving ] | |
[ text <| | |
if isSaving then | |
"Saving..." | |
else | |
"Save" | |
] | |
] | |
-- single-line | |
viewSave { isSaving } = | |
div [] | |
[ button | |
[ onClick Save, disabled isSaving ] | |
[ text (if isSaving then "Saving..." else "Save") | |
] | |
] | |
-- status-quo | |
viewFeedbackPicker suggestions = | |
let | |
prompt = | |
"or pick one..." | |
toFeedback label = | |
if label == prompt then | |
"" | |
else | |
label | |
in | |
Util.Html.dropdown prompt | |
(prompt :: suggestions) | |
toFeedback | |
-- single-line | |
viewFeedbackPicker suggestions = | |
let | |
prompt = | |
"or pick one..." | |
toFeedback label = | |
if label == prompt then "" else label | |
in | |
Util.Html.dropdown prompt | |
(prompt :: suggestions) | |
toFeedback | |
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
{- | |
Examples which I think are made worse (or not much better) by single-line formatting of `if-then-else` | |
-} | |
-- status-quo | |
adjustSelection index = | |
if index == numScreens - 1 then | |
index - 1 | |
else | |
index | |
-- single-line | |
adjustSelection index = | |
if index == numScreens - 1 then index - 1 else index | |
-- status-quo | |
themeSelector index = | |
if index == model.currentScreenIndex then | |
"btn-success" | |
else | |
"btn-default" | |
-- single-line | |
themeSelector index = | |
if index == model.currentScreenIndex then "btn-success" else "btn-default" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment