Last active
February 13, 2022 21:33
-
-
Save aspnetde/0e7b71bd7108ee62dac4d2783653c141 to your computer and use it in GitHub Desktop.
Revisions
-
aspnetde revised this gist
Jun 12, 2020 . 2 changed files with 4 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -20,7 +20,7 @@ let update props msg state = match msg with | SignOut -> state, Cmd.ofSub (fun _ -> props.SignOut()) let dashboard = React.functionComponent("Dashboard", fun props -> let state, dispatch = React.useElmish(init props, update props, [||]) Html.div [ Html.h1 (sprintf "Hi, %s!" state.User) @@ -30,6 +30,4 @@ let render = React.functionComponent("Dashboard", fun props -> prop.onClick (fun _ -> SignOut |> dispatch) ] ] ) This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -25,7 +25,7 @@ let update props msg state = | SetPassword password -> { state with Password = password }, Cmd.none | SignIn -> state, Cmd.ofSub (fun _ -> props.SignIn(state.UserName)) let login = React.functionComponent("LoginForm", fun props -> let state, dispatch = React.useElmish(init, update props, [||]) let signInPossible = @@ -58,6 +58,4 @@ let render = React.functionComponent("LoginForm", fun props -> prop.disabled (not signInPossible) ] ] ) -
aspnetde revised this gist
Jun 12, 2020 . 2 changed files with 9 additions and 13 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -13,17 +13,17 @@ type Props = type Msg = | SignOut let init props = { User = props.User }, Cmd.none let update props msg state = match msg with | SignOut -> state, Cmd.ofSub (fun _ -> props.SignOut()) let render = React.functionComponent("Dashboard", fun props -> let state, dispatch = React.useElmish(init props, update props, [||]) Html.div [ Html.h1 (sprintf "Hi, %s!" state.User) Html.hr [] Html.button [ prop.text "Sign out" @@ -32,6 +32,4 @@ let private render props hook = React.functionComponent("Dashboard", fun () -> ] ) let dashboard props = render(props) This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -25,8 +25,8 @@ let update props msg state = | SetPassword password -> { state with Password = password }, Cmd.none | SignIn -> state, Cmd.ofSub (fun _ -> props.SignIn(state.UserName)) let render = React.functionComponent("LoginForm", fun props -> let state, dispatch = React.useElmish(init, update props, [||]) let signInPossible = (not (String.IsNullOrWhiteSpace(state.UserName))) && @@ -60,6 +60,4 @@ let render props hook = React.functionComponent("LoginForm", fun () -> ] ) let login props = render(props) -
aspnetde revised this gist
Jun 12, 2020 . 2 changed files with 13 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -13,17 +13,17 @@ type Props = type Msg = | SignOut let private init props = { User = props.User }, Cmd.none let private update props msg state = match msg with | SignOut -> state, Cmd.ofSub (fun _ -> props.SignOut()) let private render props hook = React.functionComponent("Dashboard", fun () -> let (state:State), dispatch = hook() Html.div [ Html.h1 (sprintf "Hallo, %s!" state.User) Html.hr [] Html.button [ prop.text "Sign out" @@ -32,4 +32,6 @@ let render props = React.functionComponent("Dashboard", fun () -> ] ) let dashboard props = let hook () = React.useElmish(init props, update props, [||]) (render props hook)() This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -25,8 +25,8 @@ let update props msg state = | SetPassword password -> { state with Password = password }, Cmd.none | SignIn -> state, Cmd.ofSub (fun _ -> props.SignIn(state.UserName)) let render props hook = React.functionComponent("LoginForm", fun () -> let state, dispatch = hook() let signInPossible = (not (String.IsNullOrWhiteSpace(state.UserName))) && @@ -60,4 +60,6 @@ let render props = React.functionComponent("LoginForm", fun () -> ] ) let login props = let hook () = React.useElmish(init, update props, [||]) (render props hook)() -
aspnetde created this gist
Jun 12, 2020 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ module App open Elmish type State = { CurrentUser: string option } type Msg = | SignIn of string | SignOut let init() = { CurrentUser = None }, Cmd.none let update (msg: Msg) (state: State) = match msg with | SignIn user -> { state with CurrentUser = Some (user) }, Cmd.none | SignOut -> { state with CurrentUser = None }, Cmd.none let render (state: State) (dispatch: Msg -> unit) = match state.CurrentUser with | Some -> Dashboard.dashboard { User = state.CurrentUser.Value; SignOut = fun () -> SignOut |> dispatch } | None -> Login.login { SignIn = fun user -> SignIn(user) |> dispatch } This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,35 @@ module Dashboard open Elmish open Feliz.UseElmish open Feliz type State = { User: string } type Props = { User: string SignOut: unit -> unit } type Msg = | SignOut let init props = { User = props.User }, Cmd.none let update props msg state = match msg with | SignOut -> state, Cmd.ofSub (fun _ -> props.SignOut()) let render props = React.functionComponent("Dashboard", fun () -> let state, dispatch = React.useElmish(init props, update props, [||]) Html.div [ Html.h1 (sprintf "Hello, %s!" state.User) Html.hr [] Html.button [ prop.text "Sign out" prop.onClick (fun _ -> SignOut |> dispatch) ] ] ) let dashboard props = render(props)() This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,63 @@ module Login open Feliz open Feliz.UseElmish open Elmish open System type State = { UserName: string Password: string } type Props = { SignIn: string -> unit } type Msg = | SetUserName of string | SetPassword of string | SignIn let init() = { UserName = ""; Password = "" }, Cmd.none let update props msg state = match msg with | SetUserName userName -> { state with UserName = userName }, Cmd.none | SetPassword password -> { state with Password = password }, Cmd.none | SignIn -> state, Cmd.ofSub (fun _ -> props.SignIn(state.UserName)) let render props = React.functionComponent("LoginForm", fun () -> let state, dispatch = React.useElmish(init, update props, [||]) let signInPossible = (not (String.IsNullOrWhiteSpace(state.UserName))) && (not (String.IsNullOrWhiteSpace(state.Password))) Html.div [ Html.label [ prop.text "User name"; prop.htmlFor "user" ] Html.br [] Html.input [ prop.id "user" prop.type'.text prop.onChange (SetUserName >> dispatch) ] Html.br [] Html.label [ prop.text "Password"; prop.htmlFor "password" ] Html.br [] Html.input [ prop.id "password" prop.type'.password prop.onChange (SetPassword >> dispatch) ] Html.br [] Html.br [] Html.button [ prop.onClick (fun _ -> SignIn |> dispatch) prop.text "Sign in" prop.disabled (not signInPossible) ] ] ) let login props = render(props)()