Created
March 29, 2016 00:13
-
-
Save chuck0523/f70eb2204bc33478fc4f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Counter where | |
import Html exposing (..) | |
import Html.Attributes exposing (style) | |
import Html.Events exposing (onClick) | |
-- モデル | |
type alias Model = Int | |
init : Int -> Model | |
init count = count | |
-- アップデート | |
type Action = Increment | Decrement | |
update : Action -> Model -> Model | |
update action model = | |
case action of | |
Increment -> | |
model + 1 | |
Decrement -> | |
model - 1 | |
-- ビュー | |
view : Signal.Address Action -> Model -> Html | |
view address model = | |
div [] | |
[ button [ onClick address Decrement ] [ text "-" ] | |
, div [ countStyle ] [ text (toString model) ] | |
, button [ onClick address Increment ] [ text "+" ] | |
] | |
countStyle : Attribute | |
countStyle = | |
style | |
[ ("font-size", "20px") | |
, ("font-family", "monospace") | |
, ("display", "inline-block") | |
, ("width", "50px") | |
, ("text-align", "center") | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment