Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
module TripleCounter where
import Counter
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
-- モデル
type alias Model =
{ topCounter : Counter.Model
, centerCounter : Counter.Model
, bottomCounter : Counter.Model
}
init : Int -> Int -> Int -> Model
init top center bottom =
{ topCounter = Counter.init top
, centerCounter = Counter.init center
, bottomCounter = Counter.init bottom
}
-- 更新
type Action
= Reset
| Top Counter.Action
| Center Counter.Action
| Bottom Counter.Action
update : Action -> Model -> Model
update action model =
case action of
Reset -> init 0 0 0
Top act ->
{ model |
topCounter = Counter.update act model.topCounter
}
Center act ->
{ model |
centerCounter = Counter.update act model.centerCounter
}
Bottom act ->
{ model |
bottomCounter = Counter.update act model.bottomCounter
}
-- ビュー
view : Signal.Address Action -> Model -> Html
view address model =
div []
[ Counter.view (Signal.forwardTo address Top) model.topCounter
, Counter.view (Signal.forwardTo address Center) model.centerCounter
, Counter.view (Signal.forwardTo address Bottom) model.bottomCounter
, button [ onClick address Reset ] [ text "RESET" ]
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment