Last active
January 3, 2018 17:15
-
-
Save chrisbuttery/85088b92a1b2aea80b5ce4629367069b to your computer and use it in GitHub Desktop.
Elm 0.17. A simple Mouse.moves example
This file contains hidden or 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
"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" | |
} |
This file contains hidden or 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 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