forked from evancz/elm-architecture-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpinSquarePair.elm
69 lines (51 loc) · 1.24 KB
/
SpinSquarePair.elm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
module SpinSquarePair where
import Effects exposing (Effects)
import Html exposing (..)
import Html.Attributes exposing (..)
import SpinSquare
-- MODEL
type alias Model =
{ left : SpinSquare.Model
, right : SpinSquare.Model
}
init : (Model, Effects Action)
init =
let
(left, leftFx) = SpinSquare.init
(right, rightFx) = SpinSquare.init
in
( Model left right
, Effects.batch
[ Effects.map Left leftFx
, Effects.map Right rightFx
]
)
-- UPDATE
type Action
= Left SpinSquare.Action
| Right SpinSquare.Action
update : Action -> Model -> (Model, Effects Action)
update action model =
case action of
Left act ->
let
(left, fx) = SpinSquare.update act model.left
in
( Model left model.right
, Effects.map Left fx
)
Right act ->
let
(right, fx) = SpinSquare.update act model.right
in
( Model model.left right
, Effects.map Right fx
)
-- VIEW
(=>) = (,)
view : Signal.Address Action -> Model -> Html
view address model =
div [ style [ "display" => "flex" ] ]
[ SpinSquare.view (Signal.forwardTo address Left) model.left
, SpinSquare.view (Signal.forwardTo address Right) model.right
]