forked from evancz/elm-architecture-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRandomGifPair.elm
66 lines (50 loc) · 1.28 KB
/
RandomGifPair.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
module RandomGifPair where
import Effects exposing (Effects)
import Html exposing (..)
import Html.Attributes exposing (..)
import RandomGif
-- MODEL
type alias Model =
{ left : RandomGif.Model
, right : RandomGif.Model
}
init : String -> String -> (Model, Effects Action)
init leftTopic rightTopic =
let
(left, leftFx) = RandomGif.init leftTopic
(right, rightFx) = RandomGif.init rightTopic
in
( Model left right
, Effects.batch
[ Effects.map Left leftFx
, Effects.map Right rightFx
]
)
-- UPDATE
type Action
= Left RandomGif.Action
| Right RandomGif.Action
update : Action -> Model -> (Model, Effects Action)
update action model =
case action of
Left act ->
let
(left, fx) = RandomGif.update act model.left
in
( Model left model.right
, Effects.map Left fx
)
Right act ->
let
(right, fx) = RandomGif.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") ] ]
[ RandomGif.view (Signal.forwardTo address Left) model.left
, RandomGif.view (Signal.forwardTo address Right) model.right
]