From 555bfcae5aa9e834f19ca2e208a6c4b550ad3d62 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Mon, 8 Nov 2021 15:28:01 +0200 Subject: Initial commit --- src/Counter.elm | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/Counter.elm (limited to 'src/Counter.elm') diff --git a/src/Counter.elm b/src/Counter.elm new file mode 100644 index 0000000..83bb04b --- /dev/null +++ b/src/Counter.elm @@ -0,0 +1,47 @@ +module Counter exposing (..) + +import Browser +import Html exposing (Html, button, div, text) +import Html.Events exposing (onClick) + + +type alias Model = + { count : Int } + + +initialModel : Model +initialModel = + { count = 0 } + + +type Msg + = Increment + | Decrement + + +update : Msg -> Model -> Model +update msg model = + case msg of + Increment -> + { model | count = model.count + 1 } + + Decrement -> + { model | count = model.count - 1 } + + +view : Model -> Html Msg +view model = + div [] + [ button [ onClick Increment ] [ text "+1" ] + , div [] [ text <| String.fromInt model.count ] + , button [ onClick Decrement ] [ text "-1" ] + ] + + +main : Program () Model Msg +main = + Browser.sandbox + { init = initialModel + , view = view + , update = update + } -- cgit v1.3