forked from ohanhi/keyboard-extra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlainSubscriptions.elm
65 lines (46 loc) · 1.15 KB
/
PlainSubscriptions.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
module PlainSubscriptions exposing (..)
import Html exposing (Html, div, p, ul, li, text)
import Keyboard.Extra exposing (Key)
import Style
{- Subscribing to keyboard events without the whole model-update -thing. -}
subscriptions : Model -> Sub Msg
subscriptions model =
Sub.batch
[ Keyboard.Extra.downs KeyDown
, Keyboard.Extra.ups KeyUp
]
main : Program Never Model Msg
main =
Html.program
{ init = init
, update = update
, view = view
, subscriptions = subscriptions
}
type Msg
= KeyDown Key
| KeyUp Key
type alias Model =
{ events : List String
}
init : ( Model, Cmd Msg )
init =
( Model []
, Cmd.none
)
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
( { model | events = (toString msg) :: model.events }
, Cmd.none
)
view : Model -> Html msg
view model =
div [ Style.container ]
[ p [] [ text "Try pressing, releasing and long-pressing keys." ]
, keysView model
]
keysView : Model -> Html msg
keysView model =
model.events
|> List.map (\event -> li [] [ text event ])
|> ul []