Created
October 15, 2021 03:09
-
-
Save morgankenyon/de108b4480738f05a908172aef9d2e41 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
module App | |
open Elmish | |
open Elmish.React | |
open Feliz | |
type State = | |
{ Username: string | |
Password: string | |
LoggedIn: bool } | |
type Msg = | |
| UpdateUsername of string | |
| UpdatePassword of string | |
| Login | |
| ResetForm | |
let init() = | |
{ Username = "" | |
Password = "" | |
LoggedIn = false } | |
let update (msg: Msg) (state: State): State = | |
match msg with | |
| UpdateUsername username -> { state with Username = username } | |
| UpdatePassword password -> { state with Password = password } | |
| Login -> { state with LoggedIn = true } | |
| ResetForm -> { state with LoggedIn = false; Username = ""; Password = "" } | |
let render (state: State) (dispatch: Msg -> unit) = | |
Html.div [ | |
Html.div [ | |
Html.input [ | |
prop.valueOrDefault state.Username | |
prop.onChange (UpdateUsername >> dispatch) | |
] | |
] | |
Html.div [ | |
Html.input [ | |
prop.valueOrDefault state.Password | |
prop.onChange (UpdatePassword >> dispatch) | |
prop.type' "password" | |
] | |
] | |
Html.div [ | |
Html.button [ | |
prop.onClick (fun _ -> dispatch Login) | |
prop.text "Login" | |
] | |
] | |
Html.div [ | |
Html.button [ | |
prop.onClick (fun _ -> dispatch ResetForm) | |
prop.text "Reset" | |
] | |
] | |
] | |
Program.mkSimple init update render | |
|> Program.withReactSynchronous "elmish-app" | |
|> Program.run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment