Copyright | (C) 2016-2018 David M. Johnson |
---|---|
License | BSD3-style (see the file LICENSE) |
Maintainer | David M. Johnson <djohnson.m@gmail.com> |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
Synopsis
- type JSM = IO
- forkJSM :: JSM () -> JSM ()
- asyncCallback :: JSM () -> JSM Function
- asyncCallback1 :: (JSVal -> JSM ()) -> JSM Function
- callbackToJSVal :: Function -> JSM JSVal
- objectToJSVal :: Object -> JSM JSVal
- ghcjsPure :: GHCJSPure a -> JSM a
- syncPoint :: JSM ()
- addEventListener :: JSVal -> MisoString -> (JSVal -> JSM ()) -> JSM ()
- windowAddEventListener :: MisoString -> (JSVal -> JSM ()) -> JSM ()
- windowInnerHeight :: JSM Int
- windowInnerWidth :: JSM Int
- eventPreventDefault :: JSVal -> JSM ()
- eventStopPropagation :: JSVal -> JSM ()
- now :: JSM Double
- consoleLog :: MisoString -> JSM ()
- consoleLogJSVal :: JSVal -> JSM ()
- stringify :: ToJSON json => json -> JSM MisoString
- parse :: FromJSON json => JSVal -> JSM json
- clearBody :: JSM ()
- objectToJSON :: JSVal -> JSVal -> JSM JSVal
- set :: ToJSVal v => MisoString -> v -> Object -> JSM ()
- getBody :: JSM JSVal
- getDoc :: JSM JSVal
- getElementById :: MisoString -> JSM JSVal
- diff' :: Object -> Object -> JSVal -> JSVal -> JSM ()
- integralToJSString :: Integral a => a -> MisoString
- realFloatToJSString :: RealFloat a => a -> MisoString
- jsStringToDouble :: MisoString -> Double
- delegateEvent :: JSVal -> JSVal -> JSM JSVal -> JSM ()
- copyDOMIntoVTree :: Bool -> JSVal -> JSVal -> JSM ()
- swapCallbacks :: JSM ()
- releaseCallbacks :: JSM ()
- registerCallback :: JSVal -> JSM ()
- focus :: MisoString -> JSM ()
- blur :: MisoString -> JSM ()
- scrollIntoView :: MisoString -> JSM ()
- alert :: MisoString -> JSM ()
Documentation
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
asyncCallback1 :: (JSVal -> JSM ()) -> JSM Function Source #
Creates an asynchronous callback function with a single argument
ghcjsPure :: GHCJSPure a -> JSM a Source #
Used when you want to call a functions that is pure in GHCJS, but lives in the JSM in jsaddle.
:: JSVal | Event target on which we want to register event listener |
-> MisoString | Type of event to listen to (e.g. "click") |
-> (JSVal -> JSM ()) | Callback which will be called when the event occurs, the event will be passed to it as a parameter. |
-> JSM () |
Register an event listener on given target.
windowAddEventListener Source #
:: MisoString | Type of event to listen to (e.g. "click") |
-> (JSVal -> JSM ()) | Callback which will be called when the event occurs, the event will be passed to it as a parameter. |
-> JSM () |
Registers an event listener on window
windowInnerHeight :: JSM Int Source #
Retrieves the height (in pixels) of the browser window viewport including, if rendered, the horizontal scrollbar.
See https://developer.mozilla.org/en-US/docs/Web/API/Window/innerHeight
windowInnerWidth :: JSM Int Source #
Retrieves the width (in pixels) of the browser window viewport including, if rendered, the vertical scrollbar.
See https://developer.mozilla.org/en-US/docs/Web/API/Window/innerWidth
eventPreventDefault :: JSVal -> JSM () Source #
Prevent default event behavior
eventStopPropagation :: JSVal -> JSM () Source #
Stop propagation of events
Retrieve high resolution time stamp
See https://developer.mozilla.org/en-US/docs/Web/API/Performance/now
consoleLog :: MisoString -> JSM () Source #
Outputs a message to the web console
See https://developer.mozilla.org/en-US/docs/Web/API/Console/log
consoleLogJSVal :: JSVal -> JSM () Source #
Console-logging
Clear the document body. This is particularly useful to avoid creating multiple copies of your app when running in GHCJSi.
Convert a JavaScript object to JSON
Retrieves a reference to document body.
See https://developer.mozilla.org/en-US/docs/Web/API/Document/body
Retrieves a reference to the document.
See https://developer.mozilla.org/en-US/docs/Web/API/Document
getElementById :: MisoString -> JSM JSVal Source #
Returns an Element object representing the element whose id property matches the specified string.
See https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementById
Diff two virtual DOMs
integralToJSString :: Integral a => a -> MisoString Source #
Helper function for converting Integral types to JavaScript strings
realFloatToJSString :: RealFloat a => a -> MisoString Source #
Helper function for converting RealFloat types to JavaScript strings
jsStringToDouble :: MisoString -> Double Source #
Helper function for converting RealFloat types to JavaScript strings
delegateEvent :: JSVal -> JSVal -> JSM JSVal -> JSM () Source #
Initialize event delegation from a mount point.
copyDOMIntoVTree :: Bool -> JSVal -> JSVal -> JSM () Source #
Copies DOM pointers into virtual dom entry point into isomorphic javascript
swapCallbacks :: JSM () Source #
Pins down the current callbacks for clearing later
releaseCallbacks :: JSM () Source #
Releases callbacks registered by the virtual DOM.
registerCallback :: JSVal -> JSM () Source #
Mock for callback registration
focus :: MisoString -> JSM () Source #
Fails silently if the element is not found.
Analogous to document.getElementById(id).focus()
.
blur :: MisoString -> JSM () Source #
Fails silently if the element is not found.
Analogous to document.getElementById(id).blur()
scrollIntoView :: MisoString -> JSM () Source #
Calls document.getElementById(id).scrollIntoView()
alert :: MisoString -> JSM () Source #
Calls the alert()
function.