-----------------------------------------------------------------------------
{-# LANGUAGE OverloadedStrings #-}
-----------------------------------------------------------------------------
-- |
-- Module      :  Miso.Native.X.Element.Webview.Event
-- Copyright   :  (C) 2016-2026 David M. Johnson
-- License     :  BSD3-style (see the file LICENSE)
-- Maintainer  :  David M. Johnson <code@dmj.io>
-- Stability   :  experimental
-- Portability :  non-portable
--
-- @since 1.13.0.0
----------------------------------------------------------------------------
module Miso.Native.X.Element.Webview.Event
  ( -- *** Events
    onError
  , onErrorWith
  , onErrorMain
  , onErrorMainWith
  , onLoad
  , onLoadWith
  , onLoadMain
  , onLoadMainWith
  , onLocationChange
  , onLocationChangeWith
  , onLocationChangeMain
  , onLocationChangeMainWith
  , onMessage
  , onMessageWith
  , onMessageMain
  , onMessageMainWith
  , onOpenWindow
  , onOpenWindowWith
  , onOpenWindowMain
  , onOpenWindowMainWith
    -- *** Types
  , WebviewErrorEvent (..)
    -- *** Decoders
  , webviewErrorDecoder
  , urlDecoder
  , messageDecoder
    -- *** Event Map
  , webviewEvents
  ) where
-----------------------------------------------------------------------------
import qualified Data.Map as M
-----------------------------------------------------------------------------
import           Miso.Event
import           Miso.JSON
import           Miso.String (MisoString)
import           Miso.Types (Attribute, EventHandler, DOMRef)
-----------------------------------------------------------------------------
-- | The 'Events' map for the Lynx @<webview>@ element.
--
-- Combine with other element maps using @<>@ and pass the result to
-- 'Miso.Native.native', so the delegator listens for these events.
--
-- @since 1.13.0.0
webviewEvents :: Events
webviewEvents :: Events
webviewEvents
  = [(Text, Phase)] -> Events
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList
  [ (Text
"error", Phase
BUBBLE)
  , (Text
"load", Phase
BUBBLE)
  , (Text
"locationchange", Phase
BUBBLE)
  , (Text
"message", Phase
BUBBLE)
  , (Text
"openwindow", Phase
BUBBLE)
  ]
-----------------------------------------------------------------------------
-- | Payload of the @binderror@ event.
data WebviewErrorEvent
  = WebviewErrorEvent
  { WebviewErrorEvent -> Int
errorCode :: Int
    -- ^ The error code
  , WebviewErrorEvent -> Text
errorMsg :: MisoString
    -- ^ The error message
  } deriving (Int -> WebviewErrorEvent -> ShowS
[WebviewErrorEvent] -> ShowS
WebviewErrorEvent -> String
(Int -> WebviewErrorEvent -> ShowS)
-> (WebviewErrorEvent -> String)
-> ([WebviewErrorEvent] -> ShowS)
-> Show WebviewErrorEvent
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> WebviewErrorEvent -> ShowS
showsPrec :: Int -> WebviewErrorEvent -> ShowS
$cshow :: WebviewErrorEvent -> String
show :: WebviewErrorEvent -> String
$cshowList :: [WebviewErrorEvent] -> ShowS
showList :: [WebviewErrorEvent] -> ShowS
Show, WebviewErrorEvent -> WebviewErrorEvent -> Bool
(WebviewErrorEvent -> WebviewErrorEvent -> Bool)
-> (WebviewErrorEvent -> WebviewErrorEvent -> Bool)
-> Eq WebviewErrorEvent
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: WebviewErrorEvent -> WebviewErrorEvent -> Bool
== :: WebviewErrorEvent -> WebviewErrorEvent -> Bool
$c/= :: WebviewErrorEvent -> WebviewErrorEvent -> Bool
/= :: WebviewErrorEvent -> WebviewErrorEvent -> Bool
Eq)
-----------------------------------------------------------------------------
-- | t'Decoder' producing a t'WebviewErrorEvent' from the raw Lynx event payload.
--
-- Pass it to 'Miso.Event.on' \/ 'Miso.Event.onMain' when writing a handler by
-- hand; the @on*@ helpers in this module already use it.
--
-- @since 1.13.0.0
webviewErrorDecoder :: Decoder WebviewErrorEvent
webviewErrorDecoder :: Decoder WebviewErrorEvent
webviewErrorDecoder = [Text
"detail"] [Text]
-> (Value -> Parser WebviewErrorEvent) -> Decoder WebviewErrorEvent
forall a. [Text] -> (Value -> Parser a) -> Decoder a
`at` Value -> Parser WebviewErrorEvent
details
  where
    details :: Value -> Parser WebviewErrorEvent
details = Text
-> (Object -> Parser WebviewErrorEvent)
-> Value
-> Parser WebviewErrorEvent
forall a. Text -> (Object -> Parser a) -> Value -> Parser a
withObject Text
"detail" ((Object -> Parser WebviewErrorEvent)
 -> Value -> Parser WebviewErrorEvent)
-> (Object -> Parser WebviewErrorEvent)
-> Value
-> Parser WebviewErrorEvent
forall a b. (a -> b) -> a -> b
$ \Object
o ->
      Int -> Text -> WebviewErrorEvent
WebviewErrorEvent
        (Int -> Text -> WebviewErrorEvent)
-> Parser Int -> Parser (Text -> WebviewErrorEvent)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Text -> Parser Int
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"errorCode"
        Parser (Text -> WebviewErrorEvent)
-> Parser Text -> Parser WebviewErrorEvent
forall a b. Parser (a -> b) -> Parser a -> Parser b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
o Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"errorMsg"
-----------------------------------------------------------------------------
-- | Decodes the @url@ field of @bindlocationchange@ and @bindopenwindow@.
urlDecoder :: Decoder MisoString
urlDecoder :: Decoder Text
urlDecoder = [Text
"detail"] [Text] -> (Value -> Parser Text) -> Decoder Text
forall a. [Text] -> (Value -> Parser a) -> Decoder a
`at` Value -> Parser Text
details
  where
    details :: Value -> Parser Text
details = Text -> (Object -> Parser Text) -> Value -> Parser Text
forall a. Text -> (Object -> Parser a) -> Value -> Parser a
withObject Text
"detail" ((Object -> Parser Text) -> Value -> Parser Text)
-> (Object -> Parser Text) -> Value -> Parser Text
forall a b. (a -> b) -> a -> b
$ \Object
o -> Object
o Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"url"
-----------------------------------------------------------------------------
-- | Decodes the @msg@ field of @bindmessage@.
messageDecoder :: Decoder MisoString
messageDecoder :: Decoder Text
messageDecoder = [Text
"detail"] [Text] -> (Value -> Parser Text) -> Decoder Text
forall a. [Text] -> (Value -> Parser a) -> Decoder a
`at` Value -> Parser Text
details
  where
    details :: Value -> Parser Text
details = Text -> (Object -> Parser Text) -> Value -> Parser Text
forall a. Text -> (Object -> Parser a) -> Value -> Parser a
withObject Text
"detail" ((Object -> Parser Text) -> Value -> Parser Text)
-> (Object -> Parser Text) -> Value -> Parser Text
forall a b. (a -> b) -> a -> b
$ \Object
o -> Object
o Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
.: Text
"msg"
-----------------------------------------------------------------------------
-- | https://lynxjs.org/api/elements/built-in/webview.html#binderror
--
-- Triggered on a webview error.
--
onError :: (WebviewErrorEvent -> action) -> Attribute model action
onError :: forall action model.
(WebviewErrorEvent -> action) -> Attribute model action
onError WebviewErrorEvent -> action
action = Text
-> Decoder WebviewErrorEvent
-> (WebviewErrorEvent -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
Text
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on Text
"error" Decoder WebviewErrorEvent
webviewErrorDecoder (\WebviewErrorEvent
e model
_ DOMRef
_ -> WebviewErrorEvent -> action
action WebviewErrorEvent
e)
-----------------------------------------------------------------------------
-- | Like 'onError', but dispatched on the Lynx __main thread__ (@MTS@).
--
-- Runs imperatively on the MTS (no VDOM diff). Meant to be used with
-- @-XStaticPointers@.
--
-- @
-- data Action = Errored WebviewErrorEvent
--
-- view_ [ event (static (onErrorMain Errored)) ] [ "some view" ]
-- @
--
onErrorMain :: (WebviewErrorEvent -> action) -> EventHandler model action
onErrorMain :: forall action model.
(WebviewErrorEvent -> action) -> EventHandler model action
onErrorMain WebviewErrorEvent -> action
action = Text
-> Decoder WebviewErrorEvent
-> (WebviewErrorEvent -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
Text
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain Text
"error" Decoder WebviewErrorEvent
webviewErrorDecoder (\WebviewErrorEvent
e model
_ DOMRef
_ -> WebviewErrorEvent -> action
action WebviewErrorEvent
e)
-----------------------------------------------------------------------------
-- | Like 'onErrorMain', but the handler also receives read-only access to the
-- @model@ and the target element's 'DOMRef' (for imperative MTS mutation).
--
-- @
-- data Action = Errored WebviewErrorEvent Model DOMRef
--
-- view_ [ event (static (onErrorMainWith Errored)) ] [ "some view" ]
-- @
--
onErrorMainWith :: (WebviewErrorEvent -> model -> DOMRef -> action) -> EventHandler model action
onErrorMainWith :: forall model action.
(WebviewErrorEvent -> model -> DOMRef -> action)
-> EventHandler model action
onErrorMainWith WebviewErrorEvent -> model -> DOMRef -> action
action = Text
-> Decoder WebviewErrorEvent
-> (WebviewErrorEvent -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
Text
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain Text
"error" Decoder WebviewErrorEvent
webviewErrorDecoder WebviewErrorEvent -> model -> DOMRef -> action
action
-----------------------------------------------------------------------------
-- | https://lynxjs.org/api/elements/built-in/webview.html#bindload
--
-- Triggered when the webview loads successfully.
--
onLoad :: action -> Attribute model action
onLoad :: forall action model. action -> Attribute model action
onLoad action
action = Text
-> Decoder ()
-> (() -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
Text
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on Text
"load" Decoder ()
emptyDecoder (\() model
_ DOMRef
_ -> action
action)
-----------------------------------------------------------------------------
-- | Like 'onLoad', but dispatched on the Lynx __main thread__ (@MTS@).
--
-- Runs imperatively on the MTS (no VDOM diff). Meant to be used with
-- @-XStaticPointers@.
--
-- @
-- data Action = Loaded
--
-- view_ [ event (static (onLoadMain Loaded)) ] [ "some view" ]
-- @
--
onLoadMain :: action -> EventHandler model action
onLoadMain :: forall action model. action -> EventHandler model action
onLoadMain action
action = Text
-> Decoder ()
-> (() -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
Text
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain Text
"load" Decoder ()
emptyDecoder (\() model
_ DOMRef
_ -> action
action)
-----------------------------------------------------------------------------
-- | Like 'onLoadMain', but the handler also receives read-only access to the
-- @model@ and the target element's 'DOMRef' (for imperative MTS mutation).
--
-- @
-- data Action = Loaded Model DOMRef
--
-- view_ [ event (static (onLoadMainWith Loaded)) ] [ "some view" ]
-- @
--
onLoadMainWith :: (model -> DOMRef -> action) -> EventHandler model action
onLoadMainWith :: forall model action.
(model -> DOMRef -> action) -> EventHandler model action
onLoadMainWith model -> DOMRef -> action
action = Text
-> Decoder ()
-> (() -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
Text
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain Text
"load" Decoder ()
emptyDecoder (\() model
m DOMRef
ref -> model -> DOMRef -> action
action model
m DOMRef
ref)
-----------------------------------------------------------------------------
-- | https://lynxjs.org/api/elements/built-in/webview.html#bindlocationchange
--
-- *Desktop, Lynx 3.5+*. Triggered when the location changes.
--
onLocationChange :: (MisoString -> action) -> Attribute model action
onLocationChange :: forall action model. (Text -> action) -> Attribute model action
onLocationChange Text -> action
action = Text
-> Decoder Text
-> (Text -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
Text
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on Text
"locationchange" Decoder Text
urlDecoder (\Text
e model
_ DOMRef
_ -> Text -> action
action Text
e)
-----------------------------------------------------------------------------
-- | Like 'onLocationChange', but dispatched on the Lynx __main thread__ (@MTS@).
--
-- Runs imperatively on the MTS (no VDOM diff). Meant to be used with
-- @-XStaticPointers@.
--
-- @
-- data Action = LocationChanged MisoString
--
-- view_ [ event (static (onLocationChangeMain LocationChanged)) ] [ "some view" ]
-- @
--
onLocationChangeMain :: (MisoString -> action) -> EventHandler model action
onLocationChangeMain :: forall action model. (Text -> action) -> EventHandler model action
onLocationChangeMain Text -> action
action = Text
-> Decoder Text
-> (Text -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
Text
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain Text
"locationchange" Decoder Text
urlDecoder (\Text
e model
_ DOMRef
_ -> Text -> action
action Text
e)
-----------------------------------------------------------------------------
-- | Like 'onLocationChangeMain', but the handler also receives read-only access
-- to the @model@ and the target element's 'DOMRef' (for imperative MTS mutation).
--
-- @
-- data Action = LocationChanged MisoString Model DOMRef
--
-- view_ [ event (static (onLocationChangeMainWith LocationChanged)) ] [ "some view" ]
-- @
--
onLocationChangeMainWith :: (MisoString -> model -> DOMRef -> action) -> EventHandler model action
onLocationChangeMainWith :: forall model action.
(Text -> model -> DOMRef -> action) -> EventHandler model action
onLocationChangeMainWith Text -> model -> DOMRef -> action
action = Text
-> Decoder Text
-> (Text -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
Text
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain Text
"locationchange" Decoder Text
urlDecoder Text -> model -> DOMRef -> action
action
-----------------------------------------------------------------------------
-- | https://lynxjs.org/api/elements/built-in/webview.html#bindmessage
--
-- Triggered when a message is posted from JavaScript.
--
onMessage :: (MisoString -> action) -> Attribute model action
onMessage :: forall action model. (Text -> action) -> Attribute model action
onMessage Text -> action
action = Text
-> Decoder Text
-> (Text -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
Text
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on Text
"message" Decoder Text
messageDecoder (\Text
e model
_ DOMRef
_ -> Text -> action
action Text
e)
-----------------------------------------------------------------------------
-- | Like 'onMessage', but dispatched on the Lynx __main thread__ (@MTS@).
--
-- Runs imperatively on the MTS (no VDOM diff). Meant to be used with
-- @-XStaticPointers@.
--
-- @
-- data Action = Message MisoString
--
-- view_ [ event (static (onMessageMain Message)) ] [ "some view" ]
-- @
--
onMessageMain :: (MisoString -> action) -> EventHandler model action
onMessageMain :: forall action model. (Text -> action) -> EventHandler model action
onMessageMain Text -> action
action = Text
-> Decoder Text
-> (Text -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
Text
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain Text
"message" Decoder Text
messageDecoder (\Text
e model
_ DOMRef
_ -> Text -> action
action Text
e)
-----------------------------------------------------------------------------
-- | Like 'onMessageMain', but the handler also receives read-only access to the
-- @model@ and the target element's 'DOMRef' (for imperative MTS mutation).
--
-- @
-- data Action = Message MisoString Model DOMRef
--
-- view_ [ event (static (onMessageMainWith Message)) ] [ "some view" ]
-- @
--
onMessageMainWith :: (MisoString -> model -> DOMRef -> action) -> EventHandler model action
onMessageMainWith :: forall model action.
(Text -> model -> DOMRef -> action) -> EventHandler model action
onMessageMainWith Text -> model -> DOMRef -> action
action = Text
-> Decoder Text
-> (Text -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
Text
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain Text
"message" Decoder Text
messageDecoder Text -> model -> DOMRef -> action
action
-----------------------------------------------------------------------------
-- | https://lynxjs.org/api/elements/built-in/webview.html#bindopenwindow
--
-- *Desktop, Lynx 3.5+*. Triggered on an open-window event.
--
onOpenWindow :: (MisoString -> action) -> Attribute model action
onOpenWindow :: forall action model. (Text -> action) -> Attribute model action
onOpenWindow Text -> action
action = Text
-> Decoder Text
-> (Text -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
Text
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on Text
"openwindow" Decoder Text
urlDecoder (\Text
e model
_ DOMRef
_ -> Text -> action
action Text
e)
-----------------------------------------------------------------------------
-- | Like 'onOpenWindow', but dispatched on the Lynx __main thread__ (@MTS@).
--
-- Runs imperatively on the MTS (no VDOM diff). Meant to be used with
-- @-XStaticPointers@.
--
-- @
-- data Action = OpenWindow MisoString
--
-- view_ [ event (static (onOpenWindowMain OpenWindow)) ] [ "some view" ]
-- @
--
onOpenWindowMain :: (MisoString -> action) -> EventHandler model action
onOpenWindowMain :: forall action model. (Text -> action) -> EventHandler model action
onOpenWindowMain Text -> action
action = Text
-> Decoder Text
-> (Text -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
Text
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain Text
"openwindow" Decoder Text
urlDecoder (\Text
e model
_ DOMRef
_ -> Text -> action
action Text
e)
-----------------------------------------------------------------------------
-- | Like 'onOpenWindowMain', but the handler also receives read-only access to
-- the @model@ and the target element's 'DOMRef' (for imperative MTS mutation).
--
-- @
-- data Action = OpenWindow MisoString Model DOMRef
--
-- view_ [ event (static (onOpenWindowMainWith OpenWindow)) ] [ "some view" ]
-- @
--
onOpenWindowMainWith :: (MisoString -> model -> DOMRef -> action) -> EventHandler model action
onOpenWindowMainWith :: forall model action.
(Text -> model -> DOMRef -> action) -> EventHandler model action
onOpenWindowMainWith Text -> model -> DOMRef -> action
action = Text
-> Decoder Text
-> (Text -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
Text
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain Text
"openwindow" Decoder Text
urlDecoder Text -> model -> DOMRef -> action
action
-----------------------------------------------------------------------------

-----------------------------------------------------------------------------
-- | Like 'onError', but the handler also receives the target element's 'DOMRef'.
-- Use for main-thread (@MTS@) handlers that imperatively mutate the element.
onErrorWith :: (WebviewErrorEvent -> DOMRef -> action) -> Attribute model action
onErrorWith :: forall action model.
(WebviewErrorEvent -> DOMRef -> action) -> Attribute model action
onErrorWith WebviewErrorEvent -> DOMRef -> action
action = Text
-> Decoder WebviewErrorEvent
-> (WebviewErrorEvent -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
Text
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on Text
"error" Decoder WebviewErrorEvent
webviewErrorDecoder ((WebviewErrorEvent -> model -> DOMRef -> action)
 -> Attribute model action)
-> (WebviewErrorEvent -> model -> DOMRef -> action)
-> Attribute model action
forall a b. (a -> b) -> a -> b
$ \WebviewErrorEvent
v model
_ DOMRef
domRef -> WebviewErrorEvent -> DOMRef -> action
action WebviewErrorEvent
v DOMRef
domRef
-----------------------------------------------------------------------------
-- | Like 'onLoad', but the handler also receives the target element's 'DOMRef'.
-- Use for main-thread (@MTS@) handlers that imperatively mutate the element.
onLoadWith :: (DOMRef -> action) -> Attribute model action
onLoadWith :: forall action model. (DOMRef -> action) -> Attribute model action
onLoadWith DOMRef -> action
action = Text
-> Decoder ()
-> (() -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
Text
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on Text
"load" Decoder ()
emptyDecoder (\() model
_ DOMRef
ref -> DOMRef -> action
action DOMRef
ref)
-----------------------------------------------------------------------------
-- | Like 'onLocationChange', but the handler also receives the target element's 'DOMRef'.
-- Use for main-thread (@MTS@) handlers that imperatively mutate the element.
onLocationChangeWith :: (MisoString -> DOMRef -> action) -> Attribute model action
onLocationChangeWith :: forall action model.
(Text -> DOMRef -> action) -> Attribute model action
onLocationChangeWith Text -> DOMRef -> action
action = Text
-> Decoder Text
-> (Text -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
Text
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on Text
"locationchange" Decoder Text
urlDecoder ((Text -> model -> DOMRef -> action) -> Attribute model action)
-> (Text -> model -> DOMRef -> action) -> Attribute model action
forall a b. (a -> b) -> a -> b
$ \Text
v model
_ DOMRef
domRef -> Text -> DOMRef -> action
action Text
v DOMRef
domRef
-----------------------------------------------------------------------------
-- | Like 'onMessage', but the handler also receives the target element's 'DOMRef'.
-- Use for main-thread (@MTS@) handlers that imperatively mutate the element.
onMessageWith :: (MisoString -> DOMRef -> action) -> Attribute model action
onMessageWith :: forall action model.
(Text -> DOMRef -> action) -> Attribute model action
onMessageWith Text -> DOMRef -> action
action = Text
-> Decoder Text
-> (Text -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
Text
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on Text
"message" Decoder Text
messageDecoder ((Text -> model -> DOMRef -> action) -> Attribute model action)
-> (Text -> model -> DOMRef -> action) -> Attribute model action
forall a b. (a -> b) -> a -> b
$ \Text
v model
_ DOMRef
domRef -> Text -> DOMRef -> action
action Text
v DOMRef
domRef
-----------------------------------------------------------------------------
-- | Like 'onOpenWindow', but the handler also receives the target element's 'DOMRef'.
-- Use for main-thread (@MTS@) handlers that imperatively mutate the element.
onOpenWindowWith :: (MisoString -> DOMRef -> action) -> Attribute model action
onOpenWindowWith :: forall action model.
(Text -> DOMRef -> action) -> Attribute model action
onOpenWindowWith Text -> DOMRef -> action
action = Text
-> Decoder Text
-> (Text -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
Text
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on Text
"openwindow" Decoder Text
urlDecoder ((Text -> model -> DOMRef -> action) -> Attribute model action)
-> (Text -> model -> DOMRef -> action) -> Attribute model action
forall a b. (a -> b) -> a -> b
$ \Text
v model
_ DOMRef
domRef -> Text -> DOMRef -> action
action Text
v DOMRef
domRef
-----------------------------------------------------------------------------