Created
March 29, 2016 00:13
-
-
Save chuck0523/8b6eb2c63f9f92bd1a31 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 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