Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e47e2f
commit 1e39a36
Showing
4 changed files
with
51 additions
and
20 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,17 @@ | ||
open Feliz | ||
open Browser | ||
open Feliz.JSX.React | ||
open Elmish | ||
open Elmish.React | ||
|
||
let private root = document.getElementById "root" |> ReactDOM.createRoot | ||
#if DEBUG | ||
open Elmish.Debug | ||
open Elmish.HMR | ||
#endif | ||
|
||
[ App.MyComponent() |> toReact ] |> React.strictMode |> root.render | ||
Program.mkProgram Ui.init Ui.update Ui.view | ||
#if DEBUG | ||
|> Program.withConsoleTrace | ||
#endif | ||
|> Program.withReactSynchronous "root" | ||
#if DEBUG | ||
|> Program.withDebugger | ||
#endif | ||
|> Program.run |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,42 @@ | ||
module App | ||
module Ui | ||
|
||
open Browser.Dom | ||
open Feliz | ||
open Fable.Core | ||
open Fable.Remoting.Client | ||
open Elmish | ||
open Feliz.JSX.React | ||
|
||
let private loadData () = | ||
let api = | ||
Remoting.createApi () | ||
|> Remoting.withRouteBuilder Route.builder | ||
|> Remoting.buildProxy<IApi> | ||
type Model = string option | ||
|
||
async { | ||
let! data = api.Greet() | ||
console.log data | ||
window.alert $"Data received: '{data}'" | ||
} | ||
|> Async.StartImmediate | ||
type Message = | ||
| GetData | ||
| GotData of string | ||
|
||
let api = | ||
Remoting.createApi () | ||
|> Remoting.withRouteBuilder Route.builder | ||
|> Remoting.buildProxy<IApi> | ||
|
||
let init () = None, Cmd.none | ||
|
||
let update msg model = | ||
match msg with | ||
| GetData -> None, Cmd.OfAsync.perform api.Greet () GotData | ||
| GotData data -> Some data, Cmd.none | ||
|
||
[<JSX.Component>] | ||
let MyComponent () = | ||
let MyComponent model dispatch = | ||
match model with | ||
| Some model -> window.alert model | ||
| None -> () | ||
|
||
JSX.jsx | ||
$""" | ||
<button id="btnFetch" onClick={fun _ -> loadData ()}> | ||
<button onClick={fun _ -> dispatch GetData}> | ||
Fetch Data! | ||
</button> | ||
""" | ||
""" | ||
|> toReact | ||
|
||
let view model dispatch = MyComponent model dispatch |
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
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