-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathSimpleSendMsg.elm
101 lines (84 loc) · 2.4 KB
/
SimpleSendMsg.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
module Main exposing (Model, Msg(..), init, main, subscriptions, update, view)
import Animation exposing (px)
import Animation.Messenger
import Browser
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
main : Program () Model Msg
main =
Browser.element
{ init = always init
, view = view
, update = update
, subscriptions = subscriptions
}
type alias Model =
{ style : Animation.Messenger.State Msg }
init : ( Model, Cmd Msg )
init =
( { style =
Animation.style
[ Animation.opacity 1.0
]
}
, Cmd.none
)
subscriptions : Model -> Sub Msg
subscriptions model =
Animation.subscription Animate [ model.style ]
type Msg
= FadeInFadeOut
| Print String
| Animate Animation.Msg
update : Msg -> Model -> ( Model, Cmd Msg )
update action model =
case action of
FadeInFadeOut ->
( { model
| style =
Animation.interrupt
[ Animation.to
[ Animation.opacity 0
]
, Animation.Messenger.send (Print "Hi!")
, Animation.to
[ Animation.opacity 1
]
]
model.style
}
, Cmd.none
)
Print str ->
let
_ =
Debug.log "message sent" str
in
( model, Cmd.none )
Animate animMsg ->
let
( newStyle, cmd ) =
Animation.Messenger.update animMsg model.style
in
( { model
| style = newStyle
}
, cmd
)
view : Model -> Html Msg
view model =
div
(Animation.render model.style
++ [ onClick FadeInFadeOut
, style "position" "relative"
, style "margin" "100px auto"
, style "padding" "25px"
, style "width" "200px"
, style "height" "200px"
, style "cursor" "pointer"
, style "background-color" "#268bd2"
, style "color" "white"
]
)
[ text "Click to Animate! (Check console for sent message)" ]