Urara-Blog/node_modules/.pnpm-store/v3/files/ca/19b545d2ce619ef0b05a7b605ccc386b3118bb585615d8b7eb9e44700fca2f6e204533aa154abc5af568204aef13dc48fb864f76b1816e59b7a87ae8b87bcd
2022-08-14 01:14:53 +08:00

66 lines
No EOL
855 B
Text

module Main exposing (..)
-- Press buttons to increment and decrement a counter.
--
-- Read how it works:
-- https://guide.elm-lang.org/architecture/buttons.html
--
import Browser
import Html exposing (Html, button, div, text)
import Html.Events exposing (onClick)
-- MAIN
main =
Browser.sandbox { init = init, update = update, view = view }
-- MODEL
type alias Model = Int
init : Model
init =
0
-- UPDATE
type Msg
= Increment
| Decrement
update : Msg -> Model -> Model
update msg model =
case msg of
Increment ->
model + 1
Decrement ->
model - 1
-- VIEW
view : Model -> Html Msg
view model =
div []
[ button [ onClick Decrement ] [ text "-" ]
, div [] [ text (String.fromInt model) ]
, button [ onClick Increment ] [ text "+" ]
]
-- From https://elm-lang.org/examples/buttons