In [ ]:
import Browser
import Html exposing (..)
import Html.Events exposing (..)
In [ ]:
type Msg = Inc | Dec
In [ ]:
type alias Model = Int
In [ ]:
init : () -> (Model, Cmd Msg)
init _ = (0, Cmd.none)
subscriptions : Model -> Sub Msg
subscriptions _ = Sub.none
In [ ]:
view : Model -> Html Msg
view model =
div []
[ button [ onClick Inc ] [ text "+" ]
, div [] [ text (String.fromInt model) ]
, button [ onClick Dec ] [ text "-" ]
]
In [ ]:
update : Msg -> Model -> (Model, Cmd Msg)
update msg model =
case msg of
Inc -> (model + 1, Cmd.none)
Dec -> (model - 1, Cmd.none)
In [ ]:
main =
Browser.element
{ init = init
, view = view
, update = update
, subscriptions = subscriptions
}
-- compile-code