summaryrefslogtreecommitdiffstats
path: root/src/Counter.elm
diff options
context:
space:
mode:
Diffstat (limited to 'src/Counter.elm')
-rw-r--r--src/Counter.elm47
1 files changed, 47 insertions, 0 deletions
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
+ }