Skip to content

Instantly share code, notes, and snippets.

@ngw
Created October 28, 2018 16:03
Show Gist options
  • Save ngw/8cdd695decab84bdddbfbe795a5dbac8 to your computer and use it in GitHub Desktop.
Save ngw/8cdd695decab84bdddbfbe795a5dbac8 to your computer and use it in GitHub Desktop.
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