miso
Copyright(C) 2016-2026 David M. Johnson
LicenseBSD3-style (see the file LICENSE)
MaintainerDavid M. Johnson <code@dmj.io>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Miso.DSL

Description

Overview

Miso.DSL is the low-level JavaScript interop layer for miso. It provides the marshaling typeclasses, JS value types, and combinators needed to call browser APIs and exchange data with JavaScript from Haskell.

Most miso users never import this module directly — higher-level modules (Miso.FFI, Miso.Canvas, Miso.Fetch, etc.) build on top of it. Import it directly when writing custom FFI bindings or inline JS.

Marshaling

Two typeclasses handle the Haskell ↔ JavaScript boundary:

  • ToJSVal — converts a Haskell value into a JSVal. Instances exist for all primitive types, lists, tuples (up to 6), Maybe, and Map MisoString. Product record types can derive ToJSVal via GHC.Generics (sum types are not supported).
  • FromJSVal — parses a JSVal back into Haskell, returning Maybe a (Nothing on type mismatch or missing field). Use fromJSValUnchecked when the shape is guaranteed by the caller. Product record types can derive FromJSVal via GHC.Generics.

Two auxiliary classes support the calling convention:

  • ToArgs — marshals a Haskell value to a [JSVal] argument list. Tuples up to arity 6 automatically produce the correct positional list.
  • ToObject — promotes a value to a JS Object for use as the this receiver in method calls.

Accessing the global scope

-- Read a global variable
x <- jsg "innerWidth"          -- globalThis.innerWidth

-- Call a global function
jsg0 "requestAnimationFrame"   -- no args
jsg1 "parseInt" ("42" :: MisoString)  -- one arg
jsgf "encodeURIComponent" args -- arbitrary ToArgs

Property access and method calls

obj ! "name"          -- get obj.name   :: IO JSVal
obj !! 3            -- get obj[3]     :: IO JSVal
obj # "push" [val]   -- call obj.push(val) :: IO JSVal
setField obj "x" 10  -- obj.x = 10
getProp "x" obj      -- obj.x
setProp "x" 10 obj   -- obj.x = 10

Object creation

o <- create                            -- new empty object  {}
o <- createWith [("x", 1), ("y", 2)]  -- { x: 1, y: 2 }
v <- new constructor args              -- new Constructor(...args)

Callbacks

Wrap a Haskell IO action as a JS function. Variants ending in ' return the JSVal of the callback's return value.

cb  'syncCallback'  action         -- () - ()
cb1 'syncCallback1' (\x - …)     -- (x) -> ()
cb2 'syncCallback2' (\x y - …)   -- (x, y) -> ()

Always free callbacks when they are no longer needed to avoid leaks:

freeFunction cb

See also

Synopsis

Classes

class ToJSVal a where Source #

A class for marshaling Haskell values into JS

Minimal complete definition

Nothing

Methods

toJSVal :: a -> IO JSVal Source #

default toJSVal :: (Generic a, GToJSVal (Rep a)) => a -> IO JSVal Source #

Instances

Instances details
ToJSVal Color Source #

ToJSVal instance for Color

Instance details

Defined in Miso.CSS.Color

Methods

toJSVal :: Color -> IO JSVal Source #

ToJSVal CompositeOperation Source # 
Instance details

Defined in Miso.Canvas

ToJSVal DirectionType Source # 
Instance details

Defined in Miso.Canvas

ToJSVal Gradient Source # 
Instance details

Defined in Miso.Canvas

ToJSVal ImageData Source # 
Instance details

Defined in Miso.Canvas

ToJSVal LineCapType Source # 
Instance details

Defined in Miso.Canvas

ToJSVal LineJoinType Source # 
Instance details

Defined in Miso.Canvas

ToJSVal Pattern Source # 
Instance details

Defined in Miso.Canvas

ToJSVal PatternType Source # 
Instance details

Defined in Miso.Canvas

ToJSVal StyleArg Source # 
Instance details

Defined in Miso.Canvas

ToJSVal TextAlignType Source # 
Instance details

Defined in Miso.Canvas

ToJSVal TextBaselineType Source # 
Instance details

Defined in Miso.Canvas

ToJSVal Cookie Source # 
Instance details

Defined in Miso.Cookie

Methods

toJSVal :: Cookie -> IO JSVal Source #

ToJSVal CookieChangeEvent Source # 
Instance details

Defined in Miso.Cookie

ToJSVal Function Source # 
Instance details

Defined in Miso.DSL

ToJSVal Object Source # 
Instance details

Defined in Miso.DSL

Methods

toJSVal :: Object -> IO JSVal Source #

ToJSVal JSVal Source # 
Instance details

Defined in Miso.DSL

Methods

toJSVal :: JSVal -> IO JSVal Source #

ToJSVal Date Source # 
Instance details

Defined in Miso.Date

Methods

toJSVal :: Date -> IO JSVal Source #

ToJSVal DecodeTarget Source #

ToJSVal instance for DecodeTarget.

Instance details

Defined in Miso.Event.Decoder

ToJSVal Options Source # 
Instance details

Defined in Miso.Event.Types

ToJSVal Phase Source # 
Instance details

Defined in Miso.Event.Types

Methods

toJSVal :: Phase -> IO JSVal Source #

ToJSVal ArrayBuffer Source # 
Instance details

Defined in Miso.FFI.Internal

ToJSVal Blob Source # 
Instance details

Defined in Miso.FFI.Internal

Methods

toJSVal :: Blob -> IO JSVal Source #

ToJSVal CONTENT_TYPE Source # 
Instance details

Defined in Miso.FFI.Internal

ToJSVal Date Source # 
Instance details

Defined in Miso.FFI.Internal

Methods

toJSVal :: Date -> IO JSVal Source #

ToJSVal Event Source # 
Instance details

Defined in Miso.FFI.Internal

Methods

toJSVal :: Event -> IO JSVal Source #

ToJSVal File Source # 
Instance details

Defined in Miso.FFI.Internal

Methods

toJSVal :: File -> IO JSVal Source #

ToJSVal FileReader Source # 
Instance details

Defined in Miso.FFI.Internal

ToJSVal FormData Source # 
Instance details

Defined in Miso.FFI.Internal

ToJSVal Image Source # 
Instance details

Defined in Miso.FFI.Internal

Methods

toJSVal :: Image -> IO JSVal Source #

ToJSVal URLSearchParams Source # 
Instance details

Defined in Miso.FFI.Internal

ToJSVal Uint8Array Source # 
Instance details

Defined in Miso.FFI.Internal

ToJSVal Value Source # 
Instance details

Defined in Miso.DSL

Methods

toJSVal :: Value -> IO JSVal Source #

ToJSVal Media Source # 
Instance details

Defined in Miso.Media

Methods

toJSVal :: Media -> IO JSVal Source #

ToJSVal EventSource Source # 
Instance details

Defined in Miso.Runtime

ToJSVal WebSocket Source # 
Instance details

Defined in Miso.Runtime

ToJSVal Key Source #

ToJSVal instance for Key

Instance details

Defined in Miso.Types

Methods

toJSVal :: Key -> IO JSVal Source #

ToJSVal Namespace Source # 
Instance details

Defined in Miso.Types

ToJSVal URI Source # 
Instance details

Defined in Miso.Types

Methods

toJSVal :: URI -> IO JSVal Source #

ToJSVal VTree Source # 
Instance details

Defined in Miso.Types

Methods

toJSVal :: VTree -> IO JSVal Source #

ToJSVal VTreeType Source # 
Instance details

Defined in Miso.Types

ToJSVal Text Source # 
Instance details

Defined in Miso.DSL

Methods

toJSVal :: Text -> IO JSVal Source #

ToJSVal () Source # 
Instance details

Defined in Miso.DSL

Methods

toJSVal :: () -> IO JSVal Source #

ToJSVal Bool Source # 
Instance details

Defined in Miso.DSL

Methods

toJSVal :: Bool -> IO JSVal Source #

ToJSVal Char Source # 
Instance details

Defined in Miso.DSL

Methods

toJSVal :: Char -> IO JSVal Source #

ToJSVal Double Source # 
Instance details

Defined in Miso.DSL

Methods

toJSVal :: Double -> IO JSVal Source #

ToJSVal Float Source # 
Instance details

Defined in Miso.DSL

Methods

toJSVal :: Float -> IO JSVal Source #

ToJSVal Int Source # 
Instance details

Defined in Miso.DSL

Methods

toJSVal :: Int -> IO JSVal Source #

ToJSVal a => ToJSVal (IO a) Source # 
Instance details

Defined in Miso.DSL

Methods

toJSVal :: IO a -> IO JSVal Source #

ToJSVal (Array value) Source # 
Instance details

Defined in Miso.Data.Array

Methods

toJSVal :: Array value -> IO JSVal Source #

ToJSVal (Set key) Source # 
Instance details

Defined in Miso.Data.Set

Methods

toJSVal :: Set key -> IO JSVal Source #

ToJSVal a => ToJSVal (Maybe a) Source # 
Instance details

Defined in Miso.DSL

Methods

toJSVal :: Maybe a -> IO JSVal Source #

ToJSVal [Char] Source # 
Instance details

Defined in Miso.DSL

Methods

toJSVal :: [Char] -> IO JSVal Source #

ToJSVal a => ToJSVal [a] Source # 
Instance details

Defined in Miso.DSL

Methods

toJSVal :: [a] -> IO JSVal Source #

ToJSVal a => ToJSVal (Map MisoString a) Source # 
Instance details

Defined in Miso.DSL

ToJSVal (Map key value) Source # 
Instance details

Defined in Miso.Data.Map

Methods

toJSVal :: Map key value -> IO JSVal Source #

(ToJSVal a, ToJSVal b) => ToJSVal (a, b) Source # 
Instance details

Defined in Miso.DSL

Methods

toJSVal :: (a, b) -> IO JSVal Source #

(ToJSVal a, ToJSVal b, ToJSVal c) => ToJSVal (a, b, c) Source # 
Instance details

Defined in Miso.DSL

Methods

toJSVal :: (a, b, c) -> IO JSVal Source #

(ToJSVal a, ToJSVal b, ToJSVal c, ToJSVal d) => ToJSVal (a, b, c, d) Source # 
Instance details

Defined in Miso.DSL

Methods

toJSVal :: (a, b, c, d) -> IO JSVal Source #

(ToJSVal a, ToJSVal b, ToJSVal c, ToJSVal d, ToJSVal e) => ToJSVal (a, b, c, d, e) Source # 
Instance details

Defined in Miso.DSL

Methods

toJSVal :: (a, b, c, d, e) -> IO JSVal Source #

(ToJSVal a, ToJSVal b, ToJSVal c, ToJSVal d, ToJSVal e, ToJSVal f) => ToJSVal (a, b, c, d, e, f) Source # 
Instance details

Defined in Miso.DSL

Methods

toJSVal :: (a, b, c, d, e, f) -> IO JSVal Source #

class GToJSVal (f :: Type -> Type) where Source #

Methods

gToJSVal :: f a -> Object -> IO () Source #

Instances

Instances details
GToJSVal (U1 :: Type -> Type) Source # 
Instance details

Defined in Miso.DSL

Methods

gToJSVal :: U1 a -> Object -> IO () Source #

GToJSVal (V1 :: Type -> Type) Source # 
Instance details

Defined in Miso.DSL

Methods

gToJSVal :: V1 a -> Object -> IO () Source #

(GToJSVal a, GToJSVal b) => GToJSVal (a :*: b) Source # 
Instance details

Defined in Miso.DSL

Methods

gToJSVal :: (a :*: b) a0 -> Object -> IO () Source #

(TypeError ('Text "Sum types unsupported") :: Constraint, GToJSVal a, GToJSVal b) => GToJSVal (a :+: b) Source # 
Instance details

Defined in Miso.DSL

Methods

gToJSVal :: (a :+: b) a0 -> Object -> IO () Source #

GToJSVal a => GToJSVal (C1 i a) Source # 
Instance details

Defined in Miso.DSL

Methods

gToJSVal :: C1 i a a0 -> Object -> IO () Source #

GToJSVal a => GToJSVal (D1 i a) Source # 
Instance details

Defined in Miso.DSL

Methods

gToJSVal :: D1 i a a0 -> Object -> IO () Source #

(ToJSVal a, Selector s) => GToJSVal (S1 s (K1 i a :: Type -> Type)) Source # 
Instance details

Defined in Miso.DSL

Methods

gToJSVal :: S1 s (K1 i a :: Type -> Type) a0 -> Object -> IO () Source #

class FromJSVal a where Source #

A class for marshaling JS values into Haskell

Minimal complete definition

Nothing

Methods

fromJSVal :: JSVal -> IO (Maybe a) Source #

default fromJSVal :: (Generic a, GFromJSVal (Rep a)) => JSVal -> IO (Maybe a) Source #

fromJSValUnchecked :: JSVal -> IO a Source #

Instances

Instances details
FromJSVal Gradient Source # 
Instance details

Defined in Miso.Canvas

FromJSVal ImageData Source # 
Instance details

Defined in Miso.Canvas

FromJSVal Pattern Source # 
Instance details

Defined in Miso.Canvas

FromJSVal PatternType Source # 
Instance details

Defined in Miso.Canvas

FromJSVal Cookie Source # 
Instance details

Defined in Miso.Cookie

FromJSVal CookieChangeEvent Source # 
Instance details

Defined in Miso.Cookie

FromJSVal Function Source # 
Instance details

Defined in Miso.DSL

FromJSVal Object Source # 
Instance details

Defined in Miso.DSL

FromJSVal JSVal Source # 
Instance details

Defined in Miso.DSL

FromJSVal Date Source # 
Instance details

Defined in Miso.Date

FromJSVal ArrayBuffer Source # 
Instance details

Defined in Miso.FFI.Internal

FromJSVal Blob Source # 
Instance details

Defined in Miso.FFI.Internal

FromJSVal Event Source # 
Instance details

Defined in Miso.FFI.Internal

FromJSVal File Source # 
Instance details

Defined in Miso.FFI.Internal

FromJSVal FileReader Source # 
Instance details

Defined in Miso.FFI.Internal

FromJSVal FormData Source # 
Instance details

Defined in Miso.FFI.Internal

FromJSVal Image Source # 
Instance details

Defined in Miso.FFI.Internal

FromJSVal URLSearchParams Source # 
Instance details

Defined in Miso.FFI.Internal

FromJSVal Uint8Array Source # 
Instance details

Defined in Miso.FFI.Internal

FromJSVal Value Source # 
Instance details

Defined in Miso.DSL

FromJSVal Geolocation Source # 
Instance details

Defined in Miso.Navigator

FromJSVal GeolocationError Source # 
Instance details

Defined in Miso.Navigator

FromJSVal GeolocationErrorCode Source # 
Instance details

Defined in Miso.Navigator

FromJSVal Closed Source # 
Instance details

Defined in Miso.Runtime

FromJSVal Text Source # 
Instance details

Defined in Miso.DSL

FromJSVal () Source # 
Instance details

Defined in Miso.DSL

FromJSVal Bool Source # 
Instance details

Defined in Miso.DSL

FromJSVal Char Source # 
Instance details

Defined in Miso.DSL

FromJSVal Double Source # 
Instance details

Defined in Miso.DSL

FromJSVal Float Source # 
Instance details

Defined in Miso.DSL

FromJSVal Int Source # 
Instance details

Defined in Miso.DSL

FromJSVal (Array value) Source # 
Instance details

Defined in Miso.Data.Array

Methods

fromJSVal :: JSVal -> IO (Maybe (Array value)) Source #

fromJSValUnchecked :: JSVal -> IO (Array value) Source #

FromJSVal (Set key) Source # 
Instance details

Defined in Miso.Data.Set

Methods

fromJSVal :: JSVal -> IO (Maybe (Set key)) Source #

fromJSValUnchecked :: JSVal -> IO (Set key) Source #

FromJSVal body => FromJSVal (Response body) Source # 
Instance details

Defined in Miso.FFI.Internal

FromJSVal a => FromJSVal (Maybe a) Source # 
Instance details

Defined in Miso.DSL

FromJSVal [Char] Source # 
Instance details

Defined in Miso.DSL

FromJSVal a => FromJSVal [a] Source # 
Instance details

Defined in Miso.DSL

FromJSVal a => FromJSVal (Map MisoString a) Source # 
Instance details

Defined in Miso.DSL

FromJSVal (Map key value) Source # 
Instance details

Defined in Miso.Data.Map

Methods

fromJSVal :: JSVal -> IO (Maybe (Map key value)) Source #

fromJSValUnchecked :: JSVal -> IO (Map key value) Source #

(FromJSVal a, FromJSVal b) => FromJSVal (a, b) Source # 
Instance details

Defined in Miso.DSL

Methods

fromJSVal :: JSVal -> IO (Maybe (a, b)) Source #

fromJSValUnchecked :: JSVal -> IO (a, b) Source #

(FromJSVal a, FromJSVal b, FromJSVal c) => FromJSVal (a, b, c) Source # 
Instance details

Defined in Miso.DSL

Methods

fromJSVal :: JSVal -> IO (Maybe (a, b, c)) Source #

fromJSValUnchecked :: JSVal -> IO (a, b, c) Source #

(FromJSVal a, FromJSVal b, FromJSVal c, FromJSVal d) => FromJSVal (a, b, c, d) Source # 
Instance details

Defined in Miso.DSL

Methods

fromJSVal :: JSVal -> IO (Maybe (a, b, c, d)) Source #

fromJSValUnchecked :: JSVal -> IO (a, b, c, d) Source #

(FromJSVal a, FromJSVal b, FromJSVal c, FromJSVal d, FromJSVal e) => FromJSVal (a, b, c, d, e) Source # 
Instance details

Defined in Miso.DSL

Methods

fromJSVal :: JSVal -> IO (Maybe (a, b, c, d, e)) Source #

fromJSValUnchecked :: JSVal -> IO (a, b, c, d, e) Source #

(FromJSVal a, FromJSVal b, FromJSVal c, FromJSVal d, FromJSVal e, FromJSVal f) => FromJSVal (a, b, c, d, e, f) Source # 
Instance details

Defined in Miso.DSL

Methods

fromJSVal :: JSVal -> IO (Maybe (a, b, c, d, e, f)) Source #

fromJSValUnchecked :: JSVal -> IO (a, b, c, d, e, f) Source #

(FromJSVal a, FromJSVal b, FromJSVal c, FromJSVal d, FromJSVal e, FromJSVal f, FromJSVal g) => FromJSVal (a, b, c, d, e, f, g) Source # 
Instance details

Defined in Miso.DSL

Methods

fromJSVal :: JSVal -> IO (Maybe (a, b, c, d, e, f, g)) Source #

fromJSValUnchecked :: JSVal -> IO (a, b, c, d, e, f, g) Source #

(FromJSVal a, FromJSVal b, FromJSVal c, FromJSVal d, FromJSVal e, FromJSVal f, FromJSVal g, FromJSVal h) => FromJSVal (a, b, c, d, e, f, g, h) Source # 
Instance details

Defined in Miso.DSL

Methods

fromJSVal :: JSVal -> IO (Maybe (a, b, c, d, e, f, g, h)) Source #

fromJSValUnchecked :: JSVal -> IO (a, b, c, d, e, f, g, h) Source #

class GFromJSVal (f :: Type -> Type) where Source #

Methods

gFromJSVal :: Object -> IO (Maybe (f a)) Source #

Instances

Instances details
GFromJSVal (U1 :: Type -> Type) Source # 
Instance details

Defined in Miso.DSL

Methods

gFromJSVal :: Object -> IO (Maybe (U1 a)) Source #

GFromJSVal (V1 :: Type -> Type) Source # 
Instance details

Defined in Miso.DSL

Methods

gFromJSVal :: Object -> IO (Maybe (V1 a)) Source #

(GFromJSVal a, GFromJSVal b) => GFromJSVal (a :*: b) Source # 
Instance details

Defined in Miso.DSL

Methods

gFromJSVal :: Object -> IO (Maybe ((a :*: b) a0)) Source #

(TypeError ('Text "Sum types unsupported") :: Constraint, GFromJSVal a, GFromJSVal b) => GFromJSVal (a :+: b) Source # 
Instance details

Defined in Miso.DSL

Methods

gFromJSVal :: Object -> IO (Maybe ((a :+: b) a0)) Source #

GFromJSVal a => GFromJSVal (C1 i a) Source # 
Instance details

Defined in Miso.DSL

Methods

gFromJSVal :: Object -> IO (Maybe (C1 i a a0)) Source #

GFromJSVal a => GFromJSVal (D1 i a) Source # 
Instance details

Defined in Miso.DSL

Methods

gFromJSVal :: Object -> IO (Maybe (D1 i a a0)) Source #

(FromJSVal a, Selector s) => GFromJSVal (S1 s (K1 i a :: Type -> Type)) Source # 
Instance details

Defined in Miso.DSL

Methods

gFromJSVal :: Object -> IO (Maybe (S1 s (K1 i a :: Type -> Type) a0)) Source #

class ToArgs args where Source #

A class for creating arguments to a JS function

Methods

toArgs :: args -> IO [JSVal] Source #

Instances

Instances details
ToArgs Color Source #

ToArgs instance for Color

Instance details

Defined in Miso.CSS.Color

Methods

toArgs :: Color -> IO [JSVal] Source #

ToArgs CompositeOperation Source # 
Instance details

Defined in Miso.Canvas

ToArgs DirectionType Source # 
Instance details

Defined in Miso.Canvas

ToArgs Gradient Source # 
Instance details

Defined in Miso.Canvas

Methods

toArgs :: Gradient -> IO [JSVal] Source #

ToArgs ImageData Source # 
Instance details

Defined in Miso.Canvas

Methods

toArgs :: ImageData -> IO [JSVal] Source #

ToArgs LineCapType Source # 
Instance details

Defined in Miso.Canvas

ToArgs LineJoinType Source # 
Instance details

Defined in Miso.Canvas

ToArgs StyleArg Source # 
Instance details

Defined in Miso.Canvas

Methods

toArgs :: StyleArg -> IO [JSVal] Source #

ToArgs TextAlignType Source # 
Instance details

Defined in Miso.Canvas

ToArgs TextBaselineType Source # 
Instance details

Defined in Miso.Canvas

ToArgs CookieChangeEvent Source # 
Instance details

Defined in Miso.Cookie

ToArgs Function Source # 
Instance details

Defined in Miso.DSL

Methods

toArgs :: Function -> IO [JSVal] Source #

ToArgs Object Source # 
Instance details

Defined in Miso.DSL

Methods

toArgs :: Object -> IO [JSVal] Source #

ToArgs JSVal Source # 
Instance details

Defined in Miso.DSL

Methods

toArgs :: JSVal -> IO [JSVal] Source #

ToArgs MisoString Source # 
Instance details

Defined in Miso.DSL

Methods

toArgs :: MisoString -> IO [JSVal] Source #

ToArgs () Source # 
Instance details

Defined in Miso.DSL

Methods

toArgs :: () -> IO [JSVal] Source #

ToArgs Bool Source # 
Instance details

Defined in Miso.DSL

Methods

toArgs :: Bool -> IO [JSVal] Source #

ToArgs Double Source # 
Instance details

Defined in Miso.DSL

Methods

toArgs :: Double -> IO [JSVal] Source #

ToArgs Int Source # 
Instance details

Defined in Miso.DSL

Methods

toArgs :: Int -> IO [JSVal] Source #

ToArgs args => ToArgs (Maybe args) Source # 
Instance details

Defined in Miso.DSL

Methods

toArgs :: Maybe args -> IO [JSVal] Source #

ToJSVal arg => ToArgs [arg] Source # 
Instance details

Defined in Miso.DSL

Methods

toArgs :: [arg] -> IO [JSVal] Source #

(ToJSVal arg1, ToJSVal arg2) => ToArgs (arg1, arg2) Source # 
Instance details

Defined in Miso.DSL

Methods

toArgs :: (arg1, arg2) -> IO [JSVal] Source #

(ToJSVal arg1, ToJSVal arg2, ToJSVal arg3) => ToArgs (arg1, arg2, arg3) Source # 
Instance details

Defined in Miso.DSL

Methods

toArgs :: (arg1, arg2, arg3) -> IO [JSVal] Source #

(ToJSVal arg1, ToJSVal arg2, ToJSVal arg3, ToJSVal arg4) => ToArgs (arg1, arg2, arg3, arg4) Source # 
Instance details

Defined in Miso.DSL

Methods

toArgs :: (arg1, arg2, arg3, arg4) -> IO [JSVal] Source #

(ToJSVal arg1, ToJSVal arg2, ToJSVal arg3, ToJSVal arg4, ToJSVal arg5) => ToArgs (arg1, arg2, arg3, arg4, arg5) Source # 
Instance details

Defined in Miso.DSL

Methods

toArgs :: (arg1, arg2, arg3, arg4, arg5) -> IO [JSVal] Source #

(ToJSVal arg1, ToJSVal arg2, ToJSVal arg3, ToJSVal arg4, ToJSVal arg5, ToJSVal arg6) => ToArgs (arg1, arg2, arg3, arg4, arg5, arg6) Source # 
Instance details

Defined in Miso.DSL

Methods

toArgs :: (arg1, arg2, arg3, arg4, arg5, arg6) -> IO [JSVal] Source #

class ToObject a where Source #

A class for creating JS objects.

Minimal complete definition

Nothing

Methods

toObject :: a -> IO Object Source #

default toObject :: (Generic a, GToJSVal (Rep a)) => a -> IO Object Source #

Instances

Instances details
ToObject ImageData Source # 
Instance details

Defined in Miso.Canvas

ToObject Object Source # 
Instance details

Defined in Miso.DSL

ToObject JSVal Source # 
Instance details

Defined in Miso.DSL

ToObject Date Source # 
Instance details

Defined in Miso.Date

Methods

toObject :: Date -> IO Object Source #

ToObject Date Source # 
Instance details

Defined in Miso.FFI.Internal

Methods

toObject :: Date -> IO Object Source #

ToObject File Source # 
Instance details

Defined in Miso.FFI.Internal

Methods

toObject :: File -> IO Object Source #

ToObject FileReader Source # 
Instance details

Defined in Miso.FFI.Internal

ToObject Image Source # 
Instance details

Defined in Miso.FFI.Internal

ToObject URLSearchParams Source # 
Instance details

Defined in Miso.FFI.Internal

ToObject URI Source # 
Instance details

Defined in Miso.Types

Methods

toObject :: URI -> IO Object Source #

ToObject VTree Source # 
Instance details

Defined in Miso.Types

ToJSVal a => ToObject (IO a) Source # 
Instance details

Defined in Miso.DSL

Methods

toObject :: IO a -> IO Object Source #

ToObject (Array value) Source # 
Instance details

Defined in Miso.Data.Array

Methods

toObject :: Array value -> IO Object Source #

ToJSVal a => ToObject (Map MisoString a) Source # 
Instance details

Defined in Miso.DSL

Types

data JSVal Source #

A type that represents any JS value

Instances

Instances details
Eq JSVal Source # 
Instance details

Defined in Miso.DSL.FFI

Methods

(==) :: JSVal -> JSVal -> Bool #

(/=) :: JSVal -> JSVal -> Bool #

FromJSVal JSVal Source # 
Instance details

Defined in Miso.DSL

ToArgs JSVal Source # 
Instance details

Defined in Miso.DSL

Methods

toArgs :: JSVal -> IO [JSVal] Source #

ToJSVal JSVal Source # 
Instance details

Defined in Miso.DSL

Methods

toJSVal :: JSVal -> IO JSVal Source #

ToObject JSVal Source # 
Instance details

Defined in Miso.DSL

newtype Object Source #

A JS Object

Constructors

Object 

Fields

Instances

Instances details
Eq Object Source # 
Instance details

Defined in Miso.DSL

Methods

(==) :: Object -> Object -> Bool #

(/=) :: Object -> Object -> Bool #

FromJSVal Object Source # 
Instance details

Defined in Miso.DSL

ToArgs Object Source # 
Instance details

Defined in Miso.DSL

Methods

toArgs :: Object -> IO [JSVal] Source #

ToJSVal Object Source # 
Instance details

Defined in Miso.DSL

Methods

toJSVal :: Object -> IO JSVal Source #

ToObject Object Source # 
Instance details

Defined in Miso.DSL

newtype Function Source #

A JS Functionn

Constructors

Function 

Fields

Instances

Instances details
Eq Function Source # 
Instance details

Defined in Miso.DSL

FromJSVal Function Source # 
Instance details

Defined in Miso.DSL

ToArgs Function Source # 
Instance details

Defined in Miso.DSL

Methods

toArgs :: Function -> IO [JSVal] Source #

ToJSVal Function Source # 
Instance details

Defined in Miso.DSL

Utils

jsg :: MisoString -> IO JSVal Source #

Retrieves a field from globalThis

jsg0 :: MisoString -> IO JSVal Source #

Invokes a function with no argument

jsg1 :: ToJSVal arg => MisoString -> arg -> IO JSVal Source #

Invokes a function with 1 argument

jsg2 Source #

Arguments

:: (ToJSVal arg1, ToJSVal arg2) 
=> MisoString

Global function name on globalThis

-> arg1

First argument

-> arg2

Second argument

-> IO JSVal 

Invokes a function with 2 arguments

jsg3 Source #

Arguments

:: (ToJSVal arg1, ToJSVal arg2, ToJSVal arg3) 
=> MisoString

Global function name on globalThis

-> arg1

First argument

-> arg2

Second argument

-> arg3

Third argument

-> IO JSVal 

Invokes a function with 3 arguments

jsg4 :: (ToJSVal arg1, ToJSVal arg2, ToJSVal arg3, ToJSVal arg4) => MisoString -> arg1 -> arg2 -> arg3 -> arg4 -> IO JSVal Source #

Invokes a function with 4 arguments

jsg5 :: (ToJSVal arg1, ToJSVal arg2, ToJSVal arg3, ToJSVal arg4, ToJSVal arg5) => MisoString -> arg1 -> arg2 -> arg3 -> arg4 -> arg5 -> IO JSVal Source #

Invokes a function with 5 arguments

jsgf Source #

Arguments

:: ToArgs args 
=> MisoString

Global function name on globalThis

-> args

Arguments to pass to the function

-> IO JSVal 

Invokes a function with a specified argument list

global :: JSVal Source #

The globalThis object in JS.

(#) :: (ToObject object, ToArgs args) => object -> MisoString -> args -> IO JSVal infixr 2 Source #

Calls a JS function on an Object at a field with specified arguments.

setField Source #

Arguments

:: (ToObject o, ToJSVal v) 
=> o

JavaScript object to mutate

-> MisoString

Field name to set

-> v

Value to assign

-> IO () 

Sets a field on an Object at a specified field

(<##) :: (ToObject o, ToJSVal v) => o -> Int -> v -> IO () infixr 1 Source #

Sets a field on an Object at a specified index

(!) :: ToObject o => o -> MisoString -> IO JSVal Source #

Retrieves a property from an Object

listProps :: Object -> IO [MisoString] Source #

Lists the properties on a JS Object.

call Source #

Arguments

:: (ToObject obj, ToObject this, ToArgs args) 
=> obj

The function object to call

-> this

The this context to bind for the call

-> args

Arguments to pass to the function

-> IO JSVal 

Calls a JS function on an Object at a field with specified arguments.

new Source #

Arguments

:: (ToObject constructor, ToArgs args) 
=> constructor

JavaScript constructor function (e.g. jsg "Array")

-> args

Constructor arguments

-> IO JSVal 

Instantiates a new JS Object.

create :: IO Object Source #

Creates a new JS Object

createWith :: ToJSVal val => [(MisoString, val)] -> IO Object Source #

Creates a new JS Object populated with key-value pairs specified in the list. Meant for use with inline JS functionality.

update = case
 Highlight domRef -> do
   3 <- inline "hljs.highlight(domRef); return 3;" =<<
     createWith [ "domRef" =: domRef ]
   pure ()

setProp Source #

Arguments

:: ToJSVal val 
=> MisoString

Property name to set

-> val

Value to assign

-> Object

Target JavaScript object

-> IO () 

Sets a property on a JS Object

getProp Source #

Arguments

:: ToObject o 
=> MisoString

Property name to read

-> o

JavaScript object to read from

-> IO JSVal 

Retrieves a property from a JS Object

eval :: MisoString -> IO JSVal Source #

Dynamically evaluates a JS string. See eval

`eval()` is slower (not subject to JS engine optimizations) and also has security vulnerabilities (can alter other local variables).

Consider using the more performant and secure (isolated) inline function.

freeFunction :: Function -> IO () Source #

Frees references to a callback

(!!) :: ToObject object => object -> Int -> IO JSVal Source #

Lookup a property based on its index

isUndefined :: ToJSVal val => val -> IO Bool Source #

Checks if a JSVal is undefined

isNull :: ToJSVal val => val -> IO Bool Source #

Checks if a JSVal is null

jsNull :: JSVal Source #

The null value in JS.

syncCallback :: IO () -> IO JSVal Source #

A synchronous callback

syncCallback1 :: (JSVal -> IO ()) -> IO JSVal Source #

A synchronous callback with a single argument

syncCallback2 :: (JSVal -> JSVal -> IO ()) -> IO JSVal Source #

A synchronous callback with two arguments

syncCallback3 :: (JSVal -> JSVal -> JSVal -> IO ()) -> IO JSVal Source #

A synchronous callback with three arguments

syncCallback' :: IO JSVal -> IO JSVal Source #

A synchronous callback that returns a value

syncCallback1' :: (JSVal -> IO JSVal) -> IO JSVal Source #

A synchronous callback that takes a single argument and returns a value

syncCallback2' :: (JSVal -> JSVal -> IO JSVal) -> IO JSVal Source #

A synchronous callback that takes two arguments and returns a value

syncCallback3' :: (JSVal -> JSVal -> JSVal -> IO JSVal) -> IO JSVal Source #

A synchronous callback that takes three arguments and returns a value

asyncCallback :: IO () -> IO JSVal Source #

A asynchronous callback

asyncCallback1 :: (JSVal -> IO ()) -> IO JSVal Source #

A asynchronous callback with one argument

asyncCallback2 :: (JSVal -> JSVal -> IO ()) -> IO JSVal Source #

A asynchronous callback with two arguments

asyncCallback3 :: (JSVal -> JSVal -> JSVal -> IO ()) -> IO JSVal Source #

A asynchronous callback with three arguments

apply Source #

Arguments

:: (FromJSVal a, ToArgs args) 
=> Function

JavaScript function to invoke

-> args

Arguments to pass to the function

-> IO a