Last active
June 25, 2019 06:49
-
-
Save kevgathuku/b5b85ad2fbc97f67c4e240cfcc16dbdd to your computer and use it in GitHub Desktop.
Elm 0.19 Buttons example
This file contains hidden or 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
-- 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