Created
December 26, 2019 02:48
-
-
Save morgankenyon/00635a5bfb4424dc877dda8776b26d3f 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 | |
(** | |
The famous Increment/Decrement ported from Elm. | |
You can find more info about Elmish architecture and samples at https://elmish.github.io/ | |
*) | |
open Elmish | |
open Elmish.React | |
open Fable.React | |
open Fable.React.Props | |
// MODEL | |
type Model = int | |
type Msg = | |
| Increment | |
| Decrement | |
| Reset | |
let init() : Model = 0 | |
// UPDATE | |
let update (msg:Msg) (model:Model) = | |
match msg with | |
| Increment -> model + 1 | |
| Decrement -> model - 1 | |
| Reset -> 0 | |
// VIEW (rendered with React) | |
let view (model:Model) dispatch = | |
div [] | |
[ button [ OnClick (fun _ -> dispatch Increment) ] [ str "+" ] | |
div [] [ str (string model) ] | |
button [ OnClick (fun _ -> dispatch Decrement) ] [ str "-" ] | |
button [ OnClick (fun _ -> dispatch Reset) ] [ str "Reset" ] ] | |
// App | |
Program.mkSimple init update view | |
|> Program.withReactSynchronous "elmish-app" | |
|> Program.withConsoleTrace | |
|> Program.run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment