Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@chrisbuttery
Last active January 3, 2018 17:15
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save chrisbuttery/85088b92a1b2aea80b5ce4629367069b to your computer and use it in GitHub Desktop.
Save chrisbuttery/85088b92a1b2aea80b5ce4629367069b to your computer and use it in GitHub Desktop.
Elm 0.17. A simple Mouse.moves example
"version": "1.0.0",
"summary": "let people do a cool thing in a fun way",
"repository": "https://github.com/user/project.git",
"license": "BSD3",
"source-directories": [
"."
],
"exposed-modules": [],
"dependencies": {
"elm-lang/core": "4.0.0 <= v < 5.0.0",
"elm-lang/html": "1.0.0 <= v < 2.0.0",
"elm-lang/mouse": "1.0.0 <= v < 2.0.0",
},
"elm-version": "0.17.0 <= v < 0.18.0"
}
import Html exposing (Html, text, div)
import Html.App as Html
import Mouse exposing (..)
main =
Html.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 : (Model, Cmd Msg)
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 a
view model =
Html.text (toString model)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment