Copyright | (C) 2016-2025 David M. Johnson |
---|---|
License | BSD3-style (see the file LICENSE) |
Maintainer | David M. Johnson <code@dmj.io> |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
Miso.FFI
Description
Synopsis
- set :: ToJSVal v => MisoString -> v -> Object -> JSM ()
- now :: JSM Double
- consoleLog :: MisoString -> JSM ()
- consoleLog' :: JSVal -> JSM ()
- consoleError :: MisoString -> JSM ()
- consoleWarn :: MisoString -> JSM ()
- getElementById :: MisoString -> JSM JSVal
- focus :: MisoString -> JSM ()
- blur :: MisoString -> JSM ()
- alert :: MisoString -> JSM ()
- reload :: JSM ()
- addStyle :: MisoString -> JSM JSVal
- addStyleSheet :: MisoString -> JSM JSVal
- addEventListener :: JSVal -> MisoString -> (JSVal -> JSM ()) -> JSM Function
- syncCallback :: JSM () -> JSM Function
- syncCallback1 :: (JSVal -> JSM ()) -> JSM Function
- asyncCallback :: JSM () -> JSM Function
- asyncCallback1 :: (JSVal -> JSM ()) -> JSM Function
- asyncCallback2 :: (JSVal -> JSVal -> JSM ()) -> JSM Function
- flush :: JSM ()
- setDrawingContext :: MisoString -> JSM ()
- jsonStringify :: ToJSON json => json -> JSM JSVal
- jsonParse :: FromJSON json => JSVal -> JSM json
- windowInnerWidth :: JSM Int
- windowInnerHeight :: JSM Int
- newtype Image = Image JSVal
- newImage :: MisoString -> JSM Image
- newtype Date = Date JSVal
- newDate :: JSM Date
- toLocaleString :: Date -> JSM MisoString
- getSeconds :: Date -> JSM Double
- getMilliseconds :: Date -> JSM Double
- getParentComponentId :: JSVal -> JSM (Maybe Int)
- getComponentId :: JSVal -> JSM Int
- nextSibling :: JSVal -> JSM JSVal
- previousSibling :: JSVal -> JSM JSVal
- click :: () -> JSVal -> JSM ()
- files :: JSVal -> JSM [JSVal]
- data JSVal
- isOnLine :: JSM Bool
- newtype ArrayBuffer = ArrayBuffer JSVal
- newtype Blob = Blob JSVal
- newtype Uint8Array = Uint8Array JSVal
- newtype FormData = FormData JSVal
- newtype File = File JSVal
- newtype URLSearchParams = URLSearchParams JSVal
- newtype FileReader = FileReader JSVal
- newFileReader :: JSM FileReader
- fetch :: (FromJSVal success, FromJSVal error) => MisoString -> MisoString -> Maybe JSVal -> [(MisoString, MisoString)] -> (Response success -> JSM ()) -> (Response error -> JSM ()) -> CONTENT_TYPE -> JSM ()
- data Response body = Response {
- status :: Maybe Int
- headers :: Map MisoString MisoString
- errorMessage :: Maybe MisoString
- body :: body
Functions
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
Console logging of JavaScript strings.
consoleLog' :: JSVal -> JSM () Source #
Console-logging of JSVal
consoleError :: MisoString -> JSM () Source #
Outputs an error message to the web console
See https://developer.mozilla.org/en-US/docs/Web/API/Console/error
Console logging of JavaScript strings.
consoleWarn :: MisoString -> JSM () Source #
Outputs a warning message to the web console
See https://developer.mozilla.org/en-US/docs/Web/API/Console/warn
Console logging of JavaScript strings.
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
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()
alert :: MisoString -> JSM () Source #
Calls the alert()
function.
addStyle :: MisoString -> JSM JSVal Source #
Appends a style_
element containing CSS to head_
addStyle "body { background-color: green; }"
<head><style>body { background-color: green; }</style></head>
addStyleSheet :: MisoString -> JSM JSVal Source #
Appends a StyleSheet link_
element to head_
The link_
tag will contain a URL to a CSS file.
addStyleSheet "https://cdn.jsdelivr.net/npm/todomvc-common@1.0.5/base.min.css"
<head><link href="https://cdn.jsdelivr.net/npm/todomvc-common@1.0.5/base.min.css" ref="stylesheet"></head>
Arguments
:: 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 Function |
Register an event listener on given target.
syncCallback :: JSM () -> JSM Function Source #
Creates a synchronous callback function (no return value)
syncCallback1 :: (JSVal -> JSM ()) -> JSM Function Source #
Creates a synchronous callback function with one argument
asyncCallback1 :: (JSVal -> JSM ()) -> JSM Function Source #
Creates an asynchronous callback function with a single argument
asyncCallback2 :: (JSVal -> JSVal -> JSM ()) -> JSM Function Source #
Creates an asynchronous callback function with two arguments
setDrawingContext :: MisoString -> JSM () Source #
Used to select a drawing context. Users can override the default DOM renderer by implementing their own Context, and exporting it to the global scope. This opens the door to different rendering engines, ala miso-native.
jsonStringify :: ToJSON json => json -> JSM JSVal Source #
Encodes a Haskell object as a JSON string by way of a JavaScript object
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
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
Image
newImage :: MisoString -> JSM Image Source #
Smart constructor for building a Image
w/ src
attribute.
Date
toLocaleString :: Date -> JSM MisoString Source #
Component
getComponentId :: JSVal -> JSM Int Source #
Get access to the ComponentId
N.B. you * must * call this on the DOMRef, otherwise, problems.
For use in onMounted
, etc.
DOM
Element
files :: JSVal -> JSM [JSVal] Source #
When working with input of type="file", this is useful for extracting out the selected files.
update (InputClicked inputElement) = withSink $ sink -> do files_ <- files inputElement forM_ files_ $ file -> sink (Upload file) update (Upload file) = do fetch "https://localhost:8080/upload" POST (Just file) [] Successful Errorful
Since: 1.9.0.0
Re-exports
Navigator
ArrayBuffer
newtype ArrayBuffer Source #
Constructors
ArrayBuffer JSVal |
Instances
FromJSVal ArrayBuffer Source # | |
Defined in Miso.FFI.Internal Methods fromJSVal :: JSVal -> JSM (Maybe ArrayBuffer) Source # fromJSValUnchecked :: JSVal -> JSM ArrayBuffer Source # fromJSValListOf :: JSVal -> JSM (Maybe [ArrayBuffer]) Source # fromJSValUncheckedListOf :: JSVal -> JSM [ArrayBuffer] Source # | |
ToJSVal ArrayBuffer Source # | |
Defined in Miso.FFI.Internal Methods toJSVal :: ArrayBuffer -> JSM JSVal Source # toJSValListOf :: [ArrayBuffer] -> JSM JSVal Source # |
Blob
Uint8Array
newtype Uint8Array Source #
Constructors
Uint8Array JSVal |
Instances
FromJSVal Uint8Array Source # | |
Defined in Miso.FFI.Internal Methods fromJSVal :: JSVal -> JSM (Maybe Uint8Array) Source # fromJSValUnchecked :: JSVal -> JSM Uint8Array Source # fromJSValListOf :: JSVal -> JSM (Maybe [Uint8Array]) Source # fromJSValUncheckedListOf :: JSVal -> JSM [Uint8Array] Source # | |
ToJSVal Uint8Array Source # | |
Defined in Miso.FFI.Internal Methods toJSVal :: Uint8Array -> JSM JSVal Source # toJSValListOf :: [Uint8Array] -> JSM JSVal Source # |
FormData
File
URLSearchParams
newtype URLSearchParams Source #
Constructors
URLSearchParams JSVal |
Instances
FromJSVal URLSearchParams Source # | |
Defined in Miso.FFI.Internal Methods fromJSVal :: JSVal -> JSM (Maybe URLSearchParams) Source # fromJSValUnchecked :: JSVal -> JSM URLSearchParams Source # fromJSValListOf :: JSVal -> JSM (Maybe [URLSearchParams]) Source # fromJSValUncheckedListOf :: JSVal -> JSM [URLSearchParams] Source # | |
ToJSVal URLSearchParams Source # | |
Defined in Miso.FFI.Internal Methods toJSVal :: URLSearchParams -> JSM JSVal Source # toJSValListOf :: [URLSearchParams] -> JSM JSVal Source # | |
MakeObject URLSearchParams Source # | |
Defined in Miso.FFI.Internal Methods makeObject :: URLSearchParams -> JSM Object Source # |
FileReader
newtype FileReader Source #
Constructors
FileReader JSVal |
Instances
FromJSVal FileReader Source # | |
Defined in Miso.FFI.Internal Methods fromJSVal :: JSVal -> JSM (Maybe FileReader) Source # fromJSValUnchecked :: JSVal -> JSM FileReader Source # fromJSValListOf :: JSVal -> JSM (Maybe [FileReader]) Source # fromJSValUncheckedListOf :: JSVal -> JSM [FileReader] Source # | |
ToJSVal FileReader Source # | |
Defined in Miso.FFI.Internal Methods toJSVal :: FileReader -> JSM JSVal Source # toJSValListOf :: [FileReader] -> JSM JSVal Source # | |
MakeObject FileReader Source # | |
Defined in Miso.FFI.Internal Methods makeObject :: FileReader -> JSM Object Source # |
newFileReader :: JSM FileReader Source #
Smart constructor for building a FileReader
Fetch API
Arguments
:: (FromJSVal success, FromJSVal error) | |
=> MisoString | url |
-> MisoString | method |
-> Maybe JSVal | body |
-> [(MisoString, MisoString)] | headers |
-> (Response success -> JSM ()) | successful callback |
-> (Response error -> JSM ()) | errorful callback |
-> CONTENT_TYPE | content type |
-> JSM () |
Retrieve JSON via Fetch API
Basic GET of JSON using Fetch API, will be expanded upon.
See https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API