{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE OverloadedStrings #-}
module Miso.Subscription.Mouse (mouseSub) where
import Control.Monad.IO.Class
import GHCJS.Marshal
import JavaScript.Object
import JavaScript.Object.Internal
import Miso.Effect (Sub)
import Miso.FFI
mouseSub :: ((Int,Int) -> action) -> Sub action
mouseSub f = \sink -> do
windowAddEventListener "mousemove" $
\mouseEvent -> do
Just x <- fromJSVal =<< getProp "clientX" (Object mouseEvent)
Just y <- fromJSVal =<< getProp "clientY" (Object mouseEvent)
liftIO (sink $ f (x,y))