Guest User

Untitled

a guest
Oct 11th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. port module Buttons exposing (main)
  2.  
  3. import Html exposing (Html, button, div, text)
  4. import Html.Events exposing (onClick)
  5.  
  6.  
  7. main =
  8. Html.beginnerProgram { model = model, view = view, update = update }
  9.  
  10.  
  11.  
  12. -- MODEL
  13.  
  14.  
  15. type alias Model =
  16. Int
  17.  
  18.  
  19. model : Model
  20. model =
  21. 0
  22.  
  23.  
  24.  
  25. -- UPDATE
  26.  
  27.  
  28. type Msg
  29. = Increment
  30. | Decrement
  31.  
  32.  
  33. update : Msg -> Model -> Model
  34. update msg model =
  35. case msg of
  36. Increment ->
  37. model + 1
  38.  
  39. Decrement ->
  40. model - 1
  41.  
  42.  
  43.  
  44. -- VIEW
  45.  
  46.  
  47. view : Model -> Html Msg
  48. view model =
  49. div []
  50. [ button [ onClick Decrement ] [ text "-" ]
  51. , div [] [ text (toString model) ]
  52. , button [ onClick Increment ] [ text "+" ]
  53. ]
Add Comment
Please, Sign In to add comment