andeemarks
2/17/2018 - 6:18 AM

7mli7d.elm.day2.mouse-click-counting.elm

import Html exposing (Html, text, div)
import Mouse exposing (..)

main = Html.program { init = init,
       view = view, update = update, subscriptions = subscriptions }
       
-- Model

type alias Model = { count: Int }

initialModel : Model
initialModel = { count = 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 | count = model.count + 1}, 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)]