{-# 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 = liftJSM $ JSM ask
#endif
runJSM :: MonadIO m => JSM a -> JSContextRef -> m a
#ifdef ghcjs_HOST_OS
runJSM f = liftIO . const f
#else
runJSM f = liftIO . runReaderT (unJSM f)
#endif
runJSaddle :: MonadIO m => JSContextRef -> JSM a -> m a
runJSaddle = flip runJSM