{-# LANGUAGE CPP #-}
{-# LANGUAGE PatternSynonyms #-}
#ifdef ghcjs_HOST_OS
{-# OPTIONS_GHC -Wno-dodgy-exports -Wno-dodgy-imports #-}
#endif
module Language.Javascript.JSaddle.Monad (
JSM(..)
, JSContextRef
, MonadJSM
, liftJSM
, askJSM
, runJSM
, runJSaddle
, syncPoint
, syncAfter
, waitForAnimationFrame
, nextAnimationFrame
, catch
, bracket
) where
#ifndef ghcjs_HOST_OS
import Control.Monad.Trans.Reader (runReaderT, ask)
#endif
import Control.Monad.IO.Class (MonadIO(..))
import Control.Monad.Catch (catch, bracket)
import Language.Javascript.JSaddle.Types (JSM(..), MonadJSM, liftJSM, JSContextRef)
import Language.Javascript.JSaddle.Run (syncPoint, syncAfter, waitForAnimationFrame, nextAnimationFrame)
askJSM :: MonadJSM m => m JSContextRef
#ifdef ghcjs_HOST_OS
askJSM = return ()
#else
askJSM :: forall (m :: * -> *). MonadJSM m => m JSContextRef
askJSM = JSM JSContextRef -> m JSContextRef
forall (m :: * -> *) a. MonadJSM m => JSM a -> m a
liftJSM (JSM JSContextRef -> m JSContextRef)
-> JSM JSContextRef -> m JSContextRef
forall a b. (a -> b) -> a -> b
$ ReaderT JSContextRef IO JSContextRef -> JSM JSContextRef
forall a. ReaderT JSContextRef IO a -> JSM a
JSM ReaderT JSContextRef IO JSContextRef
forall (m :: * -> *) r. Monad m => ReaderT r m r
ask
#endif
runJSM :: MonadIO m => JSM a -> JSContextRef -> m a
#ifdef ghcjs_HOST_OS
runJSM f = liftIO . const f
#else
runJSM :: forall (m :: * -> *) a. MonadIO m => JSM a -> JSContextRef -> m a
runJSM JSM a
f = IO a -> m a
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO a -> m a) -> (JSContextRef -> IO a) -> JSContextRef -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ReaderT JSContextRef IO a -> JSContextRef -> IO a
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT (JSM a -> ReaderT JSContextRef IO a
forall a. JSM a -> ReaderT JSContextRef IO a
unJSM JSM a
f)
#endif
runJSaddle :: MonadIO m => JSContextRef -> JSM a -> m a
runJSaddle :: forall (m :: * -> *) a. MonadIO m => JSContextRef -> JSM a -> m a
runJSaddle = (JSM a -> JSContextRef -> m a) -> JSContextRef -> JSM a -> m a
forall a b c. (a -> b -> c) -> b -> a -> c
flip JSM a -> JSContextRef -> m a
forall (m :: * -> *) a. MonadIO m => JSM a -> JSContextRef -> m a
runJSM