-
Notifications
You must be signed in to change notification settings - Fork 0
/
CounterProgram.fs
51 lines (42 loc) · 1.66 KB
/
CounterProgram.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
namespace CounterApp
open Fabulous.XamarinNative
module CounterProgram =
type Model =
{ Count: int
Step: int
Name: string }
type Msg =
| Increment
| Decrement
| Reset
| SetStep of int
| SetName of string
type Element =
{ name: string }
type Program(host: IProgramHost) =
let initModel() =
{ Count = 0
Step = 3
Name = "FSharp" }
let init() = initModel(), Cmd.none
let update msg model =
match msg with
| Increment -> { model with Count = model.Count + model.Step }, Cmd.none
| Decrement -> { model with Count = model.Count - model.Step }, Cmd.none
| Reset -> init()
| SetStep n -> { model with Step = n }, Cmd.none
| SetName n -> { model with Name = n }, Cmd.none
let view() =
[ "_incrementButton" |> Binding.msg Increment
"_decrementButton" |> Binding.msg Decrement
"_resetButton" |> Binding.msg Reset
"_valueLabel" |> Binding.oneWay (fun m -> "Value: " + m.Count.ToString())
"_stepSizeValueLabel" |> Binding.oneWay (fun m -> m.Step)
"_stepSizeSlider" |> Binding.twoWay (fun m -> m.Step) (fun v -> SetStep(int (v)))
"_twoWayFirstTextField" |> Binding.twoWay (fun m -> m.Name) (fun v -> SetName v)
"_twoWaySecondTextField" |> Binding.twoWay (fun m -> m.Name) (fun v -> SetName v) ]
do
Program.mkProgram init update view host
|> Program.withConsoleTrace
|> Program.run
|> ignore