Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. module Main exposing (..)
  2.  
  3. import Html exposing (Html, div, text, program)
  4. import Keyboard
  5. import Mouse
  6. import Char
  7.  
  8. -- MODEL
  9. type alias Model =
  10. String
  11.  
  12. init : ( Model, Cmd Msg )
  13. init =
  14. ( "Hello", Cmd.none )
  15.  
  16. -- MESSAGES
  17. type Msg
  18. = MouseMsg Mouse.Position
  19. | KeyMsg Keyboard.KeyCode
  20.  
  21. -- VIEW
  22. view : Model -> Html Msg
  23. view model =
  24. div []
  25. [ text model ]
  26.  
  27. -- UPDATE
  28. update : Msg -> Model -> ( Model, Cmd Msg )
  29. update msg model =
  30. case msg of
  31. MouseMsg position ->
  32. ( model ++ ", " ++ toString position, Cmd.none )
  33. KeyMsg x ->
  34. ( model ++ toString (Char.fromCode x), Cmd.none )
  35.  
  36. -- SUBSCRIPTIONS
  37. subscriptions : Model -> Sub Msg
  38. subscriptions model =
  39. Sub.batch
  40. [ Keyboard.downs KeyMsg
  41. , Mouse.clicks MouseMsg
  42. ]
  43.  
  44. -- MAIN
  45. main : Program Never Model Msg
  46. main =
  47. program
  48. { init = init
  49. , view = view
  50. , update = update
  51. , subscriptions = subscriptions
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement