Using Reflex-DOM, I would like to make Event t () that fires when the browser is ready to draw the next frame, i.e. when requestAnimationFrame fires. I tried this as follows:
{-# LANGUAGE RecursiveDo, TypeFamilies #-} import Reflex.Dom import Reflex.Host.Class import GHCJS.DOM (currentWindow) import GHCJS.DOM.Window as Window import GHCJS.DOM.Types (RequestAnimationFrameCallback(..)) import GHCJS.Foreign.Callback import Control.Monad import Control.Monad.IO.Class refresh win = do (event, ref) <- newEventWithTriggerRef postGui <- askPostGui rec cb <- liftIO $ asyncCallback1 $ \_timestamp -> do scheduleNext putStrLn "about to fire the event" postGui $ void $ fireEventRef ref () putStrLn "event fired" let scheduleNext = Window.requestAnimationFrame win $ Just $ RequestAnimationFrameCallback cb liftIO scheduleNext return event
My test application is as follows:
main :: IO () main = mainWidget $ do Just win <- liftIO currentWindow tick <- refresh win display =<< count tick
However, the counter does not increase. However, both about to fire the event and event fired are printed several times in the JS browser console.
source share