Created
October 15, 2016 20:30
-
-
Save mindbat/0a130d7185e9f6553fd1198e8862d8c0 to your computer and use it in GitHub Desktop.
Elm Day 2: Track Click Position
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Html exposing (Html, text, div) | |
import Html.App as App | |
import Mouse exposing (..) | |
main = App.program { init = init, | |
view = view, update = update, subscriptions = subscriptions } | |
-- Model | |
type alias Model = { x: Int, y : Int } | |
initialModel : Model | |
initialModel = { x = 0, y = 0 } | |
init = (initialModel, Cmd.none) | |
-- Update | |
type Msg = Position Int Int | |
update: Msg -> Model -> (Model, Cmd a) | |
update msg model = case msg of | |
Position x y -> ({model | x = x, y = y}, Cmd.none) | |
-- Subscriptions | |
subscriptions: Model -> Sub Msg | |
subscriptions model = Mouse.clicks(\{x, y} -> Position x y) | |
-- View | |
-- view: Model -> Html div | |
view model = div [] [text (toString model)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment