forked from evancz/elm-architecture-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCounter.elm
45 lines (32 loc) · 805 Bytes
/
Counter.elm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
module Counter exposing (..)
import Html exposing (Html, button, div, text)
import Html.Events exposing (onClick)
import Html.Attributes exposing (style, Attribute(..))
-- MODEL
type alias Model = Int
-- UPDATE
type Msg = Increment | Decrement
update : Msg -> Model -> Model
update action model =
case action of
Increment ->
model + 1
Decrement ->
model - 1
-- VIEW
view : Model -> Html Msg
view model =
div []
[ button [ onClick Decrement ] [ text "-" ]
, div [ countStyle ] [ text (toString model) ]
, button [ onClick Increment ] [ text "+" ]
]
countStyle : Attribute a
countStyle =
style
[ ("font-size", "20px")
, ("font-family", "monospace")
, ("display", "inline-block")
, ("width", "50px")
, ("text-align", "center")
]