Skip to content

Instantly share code, notes, and snippets.

@kevgathuku
Last active June 25, 2019 06:49
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 kevgathuku/b5b85ad2fbc97f67c4e240cfcc16dbdd to your computer and use it in GitHub Desktop.
Save kevgathuku/b5b85ad2fbc97f67c4e240cfcc16dbdd to your computer and use it in GitHub Desktop.
Elm 0.19 Buttons example
-- Extracted from: https://guide.elm-lang.org
-- Read more about this program in the official Elm guide:
-- https://guide.elm-lang.org/architecture/buttons.html
module Main exposing (main)
import Browser
import Html exposing (Html, button, div, text)
import Html.Events exposing (onClick)
main =
Browser.sandbox { init = 0, update = update, view = view }
-- MODEL
type alias Model = Int
init : Model
init =
0
-- UPDATE
type Msg = Increment | Decrement
update msg model =
case msg of
Increment ->
model + 1
Decrement ->
model - 1
-- VIEW
view model =
div []
[ button [ onClick Decrement ] [ text "-" ]
, div [] [ text (String.fromInt model) ]
, button [ onClick Increment ] [ text "+" ]
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment