Created
October 28, 2018 16:03
-
-
Save ngw/8cdd695decab84bdddbfbe795a5dbac8 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
update : Msg -> Model -> ( Model, Cmd Msg ) | |
update msg model = | |
case Debug.log "msg" msg of | |
SetPassword password -> | |
( { model | | |
user = updatePassword (updatePasswordValue model.user.password password) model.user } | |
, Cmd.none ) | |
ShowPassword -> | |
( { model | | |
user = updatePassword (toggleVisible model.user.password) model.user } | |
, Cmd.none ) | |
ValidatePassword -> | |
let | |
error = firstError model.user.password | |
in | |
( { model | | |
user = updatePassword (updatePasswordError model.user.password error) model.user } | |
, Cmd.none ) | |
updatePassword : Password -> User -> User | |
updatePassword password user = | |
{ user | password = password } | |
updatePasswordValue : Password -> String -> Password | |
updatePasswordValue password newPassword = | |
{ password | value = newPassword } | |
toggleVisible: Password -> Password | |
toggleVisible password = | |
{ password | visible = not password.visible } | |
updatePasswordError : Password -> String -> Password | |
updatePasswordError password error = | |
{ password | error = error } | |
firstError : Password -> String | |
firstError password = | |
let | |
validate = validatePassword password | |
in | |
case validate of | |
Ok _ -> "" | |
Err [] -> "" | |
Err (first :: rest) -> first |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment