Safe Haskell | None |
---|---|
Language | Haskell2010 |
JSM monad keeps track of the JavaScript context
- newtype JSM a = JSM {
- unJSM :: ReaderT JSContextRef IO a
- data JSContextRef
- class (Applicative m, MonadIO m) => MonadJSM m
- liftJSM :: MonadJSM m => JSM a -> m a
- askJSM :: MonadJSM m => m JSContextRef
- runJSM :: MonadIO m => JSM a -> JSContextRef -> m a
- runJSaddle :: MonadIO m => JSContextRef -> JSM a -> m a
- syncPoint :: JSM ()
- syncAfter :: JSM a -> JSM a
- waitForAnimationFrame :: JSM Double
- nextAnimationFrame :: (Double -> JSM a) -> JSM a
- catch :: Exception e => JSM b -> (e -> JSM b) -> JSM b
- bracket :: JSM a -> (a -> JSM b) -> (a -> JSM c) -> JSM c
Types
The JSM
monad keeps track of the JavaScript execution context.
When using GHCJS it is IO
.
Given a JSM
function and a JSContextRef
you can run the
function like this...
runJSM jsmFunction javaScriptContext
JSM | |
|
data JSContextRef Source #
Identifies a JavaScript execution context. When using GHCJS this is just '()' since their is only one context. When using GHC it includes the functions JSaddle needs to communicate with the JavaScript context.
class (Applicative m, MonadIO m) => MonadJSM m Source #
MonadJSM JSM Source # | |
MonadJSM m => MonadJSM (ListT m) Source # | |
MonadJSM m => MonadJSM (MaybeT m) Source # | |
MonadJSM m => MonadJSM (IdentityT * m) Source # | |
(Error e, MonadJSM m) => MonadJSM (ErrorT e m) Source # | |
MonadJSM m => MonadJSM (ExceptT e m) Source # | |
MonadJSM m => MonadJSM (StateT s m) Source # | |
MonadJSM m => MonadJSM (StateT s m) Source # | |
(Monoid w, MonadJSM m) => MonadJSM (WriterT w m) Source # | |
(Monoid w, MonadJSM m) => MonadJSM (WriterT w m) Source # | |
MonadJSM m => MonadJSM (ContT * r m) Source # | |
MonadJSM m => MonadJSM (ReaderT * r m) Source # | |
(Monoid w, MonadJSM m) => MonadJSM (RWST r w s m) Source # | |
(Monoid w, MonadJSM m) => MonadJSM (RWST r w s m) Source # | |
Running JavaScript in a JavaScript context
askJSM :: MonadJSM m => m JSContextRef Source #
Gets the JavaScript context from the monad
runJSM :: MonadIO m => JSM a -> JSContextRef -> m a Source #
Runs a JSM
JavaScript function in a given JavaScript context.
runJSaddle :: MonadIO m => JSContextRef -> JSM a -> m a Source #
Alternative version of runJSM
Syncronizing with the JavaScript context
waitForAnimationFrame :: JSM Double Source #
On GHCJS this is waitForAnimationFrame
.
On GHC it will delay the execution of the current batch of asynchronous
command when they are sent to JavaScript. It will not delay the Haskell
code execution. The time returned will be based on the Haskell clock
(not the JavaScript clock).
nextAnimationFrame :: (Double -> JSM a) -> JSM a Source #
Tries to executes the given code in the next animation frame callback. Avoid synchronous opperations where possible.