Skip to content

Instantly share code, notes, and snippets.

@mindbat
Created October 15, 2016 19:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mindbat/7afc23cad8da000e4b26de55986d4eaf to your computer and use it in GitHub Desktop.
Save mindbat/7afc23cad8da000e4b26de55986d4eaf to your computer and use it in GitHub Desktop.
Elm Day 2: Mouse Position
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.moves(\{x, y} -> Position x y)
-- View
-- view: Model -> Html div
view model = div [] [text (toString model)]
@andeemarks
Copy link

I needed to remove the Html.App import (line #2) and change App.program to Html.program (line #5) to run on 0.18

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment