-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathApp.fs
58 lines (45 loc) · 1.37 KB
/
App.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
module Sample.App
open Browser
open Elmish
open Elmish.HMR
open Lit
open Lit.Elmish
open Components
let private hmr = HMR.createToken()
Clock.register()
let init() =
{ Value = "World"
ShowClock = true
ShowReact = true }, Cmd.none
let update msg model =
match msg with
| ChangeValue v -> { model with Value = v }, Cmd.none
| ToggleClock v -> { model with ShowClock = v }, Cmd.none
| ToggleReact v -> { model with ShowReact = v }, Cmd.none
let view model dispatch =
html $"""
<div class="vertical-container" style="margin-left: 2rem;">
<button class="button"
style="margin: 1rem 0"
@click={Ev(fun _ -> not model.ShowReact |> ToggleReact |> dispatch)}>
{if model.ShowReact then "Hide" else "Show"} React
</button>
{if not model.ShowReact then Lit.nothing
else ReactLitComponent model.ShowClock}
<br />
{elmishNameInput model.Value (ChangeValue >> dispatch)}
{LocalNameInput()}
{ClockDisplay model dispatch}
</div>
"""
// Program.mkProgram init update view
// |> Program.withLit "app-container"
// |> Program.run
[<LitElement("sample-app")>]
let App() =
Hook.useHmr(hmr)
let _ = LitElement.init(fun config ->
config.useShadowDom <- false
)
let model, dispatch = Hook.useElmish(init, update)
view model dispatch