Skip to content

Instantly share code, notes, and snippets.

@chuck0523
Created March 29, 2016 00:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chuck0523/8b6eb2c63f9f92bd1a31 to your computer and use it in GitHub Desktop.
Save chuck0523/8b6eb2c63f9f92bd1a31 to your computer and use it in GitHub Desktop.
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