Skip to content

Instantly share code, notes, and snippets.

@morgankenyon
Created December 26, 2019 02:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save morgankenyon/00635a5bfb4424dc877dda8776b26d3f to your computer and use it in GitHub Desktop.
Save morgankenyon/00635a5bfb4424dc877dda8776b26d3f to your computer and use it in GitHub Desktop.
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