-----------------------------------------------------------------------------
{-# LANGUAGE OverloadedStrings #-}
-----------------------------------------------------------------------------
-- |
-- Module      :  Miso.Native.Element.Image.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
----------------------------------------------------------------------------
module Miso.Native.Element.Image.Event
  ( -- *** Events
    onLoad
  , onLoadWith
  , onLoadMain
  , onLoadMainWith
  , onError
  , onErrorWith
  , onErrorMain
  , onErrorMainWith
  , onStartPlay
  , onStartPlayWith
  , onStartPlayMain
  , onStartPlayMainWith
  , onCurrentLoopComplete
  , onCurrentLoopCompleteWith
  , onCurrentLoopCompleteMain
  , onCurrentLoopCompleteMainWith
  , onFinalLoopComplete
  , onFinalLoopCompleteWith
  , onFinalLoopCompleteMain
  , onFinalLoopCompleteMainWith
  -- *** Decoder
  , imageLoadDecoder
  , imageErrorDecoder
  -- *** Types
  , ImageErrorEvent (..)
  , ImageLoadEvent (..)
  -- *** Event Map
  , imageEvents
  ) where
-----------------------------------------------------------------------------
import qualified Data.Map as M
-----------------------------------------------------------------------------
import           Miso.Event
import           Miso.JSON
import           Miso.String (MisoString)
import           Miso.Types (Attribute, EventHandler, DOMRef)
-----------------------------------------------------------------------------
imageEvents :: Events
imageEvents :: Events
imageEvents
  = [(MisoString, Phase)] -> Events
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList
  [ (MisoString
"load", Phase
BUBBLE)
  , (MisoString
"error", Phase
BUBBLE)
  , (MisoString
"startplay", Phase
BUBBLE)
  , (MisoString
"currentloopcomplete", Phase
BUBBLE)
  , (MisoString
"finalloopcomplete", Phase
BUBBLE)
  ]
----------------------------------------------------------------------------
-- | https://lynxjs.org/api/elements/built-in/image.html#bindload
--
-- Triggered when the image request succeeds, outputting the image's width and height.
--
-- @
--
-- data Action = HandleImageLoad ImageLoadEvent
--
-- view :: context -> props -> Model -> View context Action
-- view model = image_ "url" [ onLoad HandleImageLoad ]
--
-- update :: Action -> Effect context props Model Action
-- update (HandleImageLoad ImageLoadEvent {..}) = do
--   io_ (consoleLog "image load event received")
--
-- @
--
onLoad :: (ImageLoadEvent -> action) -> Attribute model action
onLoad :: forall action model.
(ImageLoadEvent -> action) -> Attribute model action
onLoad ImageLoadEvent -> action
action = MisoString
-> Decoder ImageLoadEvent
-> (ImageLoadEvent -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"load" Decoder ImageLoadEvent
imageLoadDecoder (\ImageLoadEvent
e model
_ DOMRef
_ -> ImageLoadEvent -> action
action ImageLoadEvent
e)
-----------------------------------------------------------------------------
-- | 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 = HandleImageLoad ImageLoadEvent
--
-- view_ [ event (static (onLoadMain HandleImageLoad)) ] [ "some view" ]
-- @
--
onLoadMain :: (ImageLoadEvent -> action) -> EventHandler model action
onLoadMain :: forall action model.
(ImageLoadEvent -> action) -> EventHandler model action
onLoadMain ImageLoadEvent -> action
action = MisoString
-> Decoder ImageLoadEvent
-> (ImageLoadEvent -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"load" Decoder ImageLoadEvent
imageLoadDecoder (\ImageLoadEvent
e model
_ DOMRef
_ -> ImageLoadEvent -> action
action ImageLoadEvent
e)
-----------------------------------------------------------------------------
-- | 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 = HandleImageLoad ImageLoadEvent Model DOMRef
--
-- view_ [ event (static (onLoadMainWith HandleImageLoad)) ] [ "some view" ]
-- @
--
onLoadMainWith :: (ImageLoadEvent -> model -> DOMRef -> action) -> EventHandler model action
onLoadMainWith :: forall model action.
(ImageLoadEvent -> model -> DOMRef -> action)
-> EventHandler model action
onLoadMainWith ImageLoadEvent -> model -> DOMRef -> action
action = MisoString
-> Decoder ImageLoadEvent
-> (ImageLoadEvent -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"load" Decoder ImageLoadEvent
imageLoadDecoder ImageLoadEvent -> model -> DOMRef -> action
action
-----------------------------------------------------------------------------
-- | https://lynxjs.org/api/elements/built-in/image.html#binderror
--
-- Triggered when the image request fails, outputting the error message and code.
--
-- @
--
-- data Action = HandleImageError ImageErrorEvent
--
-- view :: context -> props -> Model -> View context Action
-- view _ _ model = image_ "url" [ onError HandleImageError ]
--
-- update :: Action -> Effect context props Model Action
-- update (HandleImageError ImageErrorEvent {..}) = do
--   io_ (consoleLog "image error event received")
--
-- @
--
onError :: (ImageErrorEvent -> action) -> Attribute model action
onError :: forall action model.
(ImageErrorEvent -> action) -> Attribute model action
onError ImageErrorEvent -> action
action = MisoString
-> Decoder ImageErrorEvent
-> (ImageErrorEvent -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"error" Decoder ImageErrorEvent
imageErrorDecoder (\ImageErrorEvent
e model
_ DOMRef
_ -> ImageErrorEvent -> action
action ImageErrorEvent
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 = HandleImageError ImageErrorEvent
--
-- view_ [ event (static (onErrorMain HandleImageError)) ] [ "some view" ]
-- @
--
onErrorMain :: (ImageErrorEvent -> action) -> EventHandler model action
onErrorMain :: forall action model.
(ImageErrorEvent -> action) -> EventHandler model action
onErrorMain ImageErrorEvent -> action
action = MisoString
-> Decoder ImageErrorEvent
-> (ImageErrorEvent -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"error" Decoder ImageErrorEvent
imageErrorDecoder (\ImageErrorEvent
e model
_ DOMRef
_ -> ImageErrorEvent -> action
action ImageErrorEvent
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 = HandleImageError ImageErrorEvent Model DOMRef
--
-- view_ [ event (static (onErrorMainWith HandleImageError)) ] [ "some view" ]
-- @
--
onErrorMainWith :: (ImageErrorEvent -> model -> DOMRef -> action) -> EventHandler model action
onErrorMainWith :: forall model action.
(ImageErrorEvent -> model -> DOMRef -> action)
-> EventHandler model action
onErrorMainWith ImageErrorEvent -> model -> DOMRef -> action
action = MisoString
-> Decoder ImageErrorEvent
-> (ImageErrorEvent -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"error" Decoder ImageErrorEvent
imageErrorDecoder ImageErrorEvent -> model -> DOMRef -> action
action
-----------------------------------------------------------------------------
-- | https://lynxjs.org/api/elements/built-in/image.html#bindstartplay
--
-- Triggered when the animated image starts playing.
--
-- @
--
-- data Action = HandleStartPlay
--
-- view :: context -> props -> Model -> View context Action
-- view _ _ model = image_ "url" [ onStartPlay HandleStartPlay ]
--
-- @
--
onStartPlay :: action -> Attribute model action
onStartPlay :: forall action model. action -> Attribute model action
onStartPlay action
action = MisoString
-> Decoder ()
-> (() -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"startplay" Decoder ()
emptyDecoder (\() model
_ DOMRef
_ -> action
action)
-----------------------------------------------------------------------------
-- | Like 'onStartPlay', but dispatched on the Lynx __main thread__ ('MTS').
--
-- Runs imperatively on the MTS (no VDOM diff). Meant to be used with
-- @-XStaticPointers@.
--
-- @
-- data Action = HandleStartPlay
--
-- view_ [ event (static (onStartPlayMain HandleStartPlay)) ] [ "some view" ]
-- @
--
onStartPlayMain :: action -> EventHandler model action
onStartPlayMain :: forall action model. action -> EventHandler model action
onStartPlayMain action
action = MisoString
-> Decoder ()
-> (() -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"startplay" Decoder ()
emptyDecoder (\() model
_ DOMRef
_ -> action
action)
-----------------------------------------------------------------------------
-- | Like 'onStartPlayMain', but the handler also receives read-only access to
-- the @model@ and the target element's 'DOMRef' (for imperative MTS mutation).
--
-- @
-- data Action = HandleStartPlay Model DOMRef
--
-- view_ [ event (static (onStartPlayMainWith HandleStartPlay)) ] [ "some view" ]
-- @
--
onStartPlayMainWith :: (model -> DOMRef -> action) -> EventHandler model action
onStartPlayMainWith :: forall model action.
(model -> DOMRef -> action) -> EventHandler model action
onStartPlayMainWith model -> DOMRef -> action
action = MisoString
-> Decoder ()
-> (() -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"startplay" Decoder ()
emptyDecoder (\() model
m DOMRef
ref -> model -> DOMRef -> action
action model
m DOMRef
ref)
-----------------------------------------------------------------------------
-- | https://lynxjs.org/api/elements/built-in/image.html#bindcurrentloopcomplete
--
-- Triggered when one loop of the animated image finishes playing.
--
-- @
--
-- data Action = HandleCurrentLoopComplete
--
-- view :: context -> props -> Model -> View context Action
-- view _ _ model = image_ "url" [ onCurrentLoopComplete HandleCurrentLoopComplete ]
--
-- @
--
onCurrentLoopComplete :: action -> Attribute model action
onCurrentLoopComplete :: forall action model. action -> Attribute model action
onCurrentLoopComplete action
action = MisoString
-> Decoder ()
-> (() -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"currentloopcomplete" Decoder ()
emptyDecoder (\() model
_ DOMRef
_ -> action
action)
-----------------------------------------------------------------------------
-- | Like 'onCurrentLoopComplete', but dispatched on the Lynx __main thread__ ('MTS').
--
-- Runs imperatively on the MTS (no VDOM diff). Meant to be used with
-- @-XStaticPointers@.
--
-- @
-- data Action = HandleCurrentLoopComplete
--
-- view_ [ event (static (onCurrentLoopCompleteMain HandleCurrentLoopComplete)) ] [ "some view" ]
-- @
--
onCurrentLoopCompleteMain :: action -> EventHandler model action
onCurrentLoopCompleteMain :: forall action model. action -> EventHandler model action
onCurrentLoopCompleteMain action
action = MisoString
-> Decoder ()
-> (() -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"currentloopcomplete" Decoder ()
emptyDecoder (\() model
_ DOMRef
_ -> action
action)
-----------------------------------------------------------------------------
-- | Like 'onCurrentLoopCompleteMain', but the handler also receives read-only
-- access to the @model@ and the target element's 'DOMRef' (for imperative MTS
-- mutation).
--
-- @
-- data Action = HandleCurrentLoopComplete Model DOMRef
--
-- view_ [ event (static (onCurrentLoopCompleteMainWith HandleCurrentLoopComplete)) ] [ "some view" ]
-- @
--
onCurrentLoopCompleteMainWith :: (model -> DOMRef -> action) -> EventHandler model action
onCurrentLoopCompleteMainWith :: forall model action.
(model -> DOMRef -> action) -> EventHandler model action
onCurrentLoopCompleteMainWith model -> DOMRef -> action
action = MisoString
-> Decoder ()
-> (() -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"currentloopcomplete" Decoder ()
emptyDecoder (\() model
m DOMRef
ref -> model -> DOMRef -> action
action model
m DOMRef
ref)
-----------------------------------------------------------------------------
-- | https://lynxjs.org/api/elements/built-in/image.html#bindfinalloopcomplete
--
-- Triggered when the animated image finishes playing all 'loopCount_' loops.
--
-- @
--
-- data Action = HandleFinalLoopComplete
--
-- view :: context -> props -> Model -> View context Action
-- view _ _ model = image_ "url" [ onFinalLoopComplete HandleFinalLoopComplete ]
--
-- @
--
onFinalLoopComplete :: action -> Attribute model action
onFinalLoopComplete :: forall action model. action -> Attribute model action
onFinalLoopComplete action
action = MisoString
-> Decoder ()
-> (() -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"finalloopcomplete" Decoder ()
emptyDecoder (\() model
_ DOMRef
_ -> action
action)
-----------------------------------------------------------------------------
-- | Like 'onFinalLoopComplete', but dispatched on the Lynx __main thread__ ('MTS').
--
-- Runs imperatively on the MTS (no VDOM diff). Meant to be used with
-- @-XStaticPointers@.
--
-- @
-- data Action = HandleFinalLoopComplete
--
-- view_ [ event (static (onFinalLoopCompleteMain HandleFinalLoopComplete)) ] [ "some view" ]
-- @
--
onFinalLoopCompleteMain :: action -> EventHandler model action
onFinalLoopCompleteMain :: forall action model. action -> EventHandler model action
onFinalLoopCompleteMain action
action = MisoString
-> Decoder ()
-> (() -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"finalloopcomplete" Decoder ()
emptyDecoder (\() model
_ DOMRef
_ -> action
action)
-----------------------------------------------------------------------------
-- | Like 'onFinalLoopCompleteMain', but the handler also receives read-only
-- access to the @model@ and the target element's 'DOMRef' (for imperative MTS
-- mutation).
--
-- @
-- data Action = HandleFinalLoopComplete Model DOMRef
--
-- view_ [ event (static (onFinalLoopCompleteMainWith HandleFinalLoopComplete)) ] [ "some view" ]
-- @
--
onFinalLoopCompleteMainWith :: (model -> DOMRef -> action) -> EventHandler model action
onFinalLoopCompleteMainWith :: forall model action.
(model -> DOMRef -> action) -> EventHandler model action
onFinalLoopCompleteMainWith model -> DOMRef -> action
action = MisoString
-> Decoder ()
-> (() -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"finalloopcomplete" Decoder ()
emptyDecoder (\() model
m DOMRef
ref -> model -> DOMRef -> action
action model
m DOMRef
ref)
-----------------------------------------------------------------------------
-- | Callback when an 'image_' fails to load
data ImageErrorEvent
  = ImageErrorEvent
  { ImageErrorEvent -> MisoString
errorMessage :: MisoString
    -- ^ error message
  , ImageErrorEvent -> Int
errorCode :: Int
    -- ^ error code
  , ImageErrorEvent -> Int
lynxCategorizedCode :: Int
    -- ^ lynx specific error code
  } deriving (Int -> ImageErrorEvent -> ShowS
[ImageErrorEvent] -> ShowS
ImageErrorEvent -> String
(Int -> ImageErrorEvent -> ShowS)
-> (ImageErrorEvent -> String)
-> ([ImageErrorEvent] -> ShowS)
-> Show ImageErrorEvent
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ImageErrorEvent -> ShowS
showsPrec :: Int -> ImageErrorEvent -> ShowS
$cshow :: ImageErrorEvent -> String
show :: ImageErrorEvent -> String
$cshowList :: [ImageErrorEvent] -> ShowS
showList :: [ImageErrorEvent] -> ShowS
Show, ImageErrorEvent -> ImageErrorEvent -> Bool
(ImageErrorEvent -> ImageErrorEvent -> Bool)
-> (ImageErrorEvent -> ImageErrorEvent -> Bool)
-> Eq ImageErrorEvent
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ImageErrorEvent -> ImageErrorEvent -> Bool
== :: ImageErrorEvent -> ImageErrorEvent -> Bool
$c/= :: ImageErrorEvent -> ImageErrorEvent -> Bool
/= :: ImageErrorEvent -> ImageErrorEvent -> Bool
Eq)
-----------------------------------------------------------------------------
-- | Callback when an 'image_' succeeds in loading
data ImageLoadEvent
  = ImageLoadEvent
  { ImageLoadEvent -> Int
imageWidth :: Int
    -- ^ 'image_' width
  , ImageLoadEvent -> Int
imageHeight :: Int
    -- ^ 'image_' height
  } deriving (Int -> ImageLoadEvent -> ShowS
[ImageLoadEvent] -> ShowS
ImageLoadEvent -> String
(Int -> ImageLoadEvent -> ShowS)
-> (ImageLoadEvent -> String)
-> ([ImageLoadEvent] -> ShowS)
-> Show ImageLoadEvent
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ImageLoadEvent -> ShowS
showsPrec :: Int -> ImageLoadEvent -> ShowS
$cshow :: ImageLoadEvent -> String
show :: ImageLoadEvent -> String
$cshowList :: [ImageLoadEvent] -> ShowS
showList :: [ImageLoadEvent] -> ShowS
Show, ImageLoadEvent -> ImageLoadEvent -> Bool
(ImageLoadEvent -> ImageLoadEvent -> Bool)
-> (ImageLoadEvent -> ImageLoadEvent -> Bool) -> Eq ImageLoadEvent
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ImageLoadEvent -> ImageLoadEvent -> Bool
== :: ImageLoadEvent -> ImageLoadEvent -> Bool
$c/= :: ImageLoadEvent -> ImageLoadEvent -> Bool
/= :: ImageLoadEvent -> ImageLoadEvent -> Bool
Eq)
-----------------------------------------------------------------------------
imageLoadDecoder :: Decoder ImageLoadEvent
imageLoadDecoder :: Decoder ImageLoadEvent
imageLoadDecoder = [MisoString
"detail"] [MisoString]
-> (Value -> Parser ImageLoadEvent) -> Decoder ImageLoadEvent
forall a. [MisoString] -> (Value -> Parser a) -> Decoder a
`at` Value -> Parser ImageLoadEvent
details
  where
    details :: Value -> Parser ImageLoadEvent
details = MisoString
-> (Object -> Parser ImageLoadEvent)
-> Value
-> Parser ImageLoadEvent
forall a. MisoString -> (Object -> Parser a) -> Value -> Parser a
withObject MisoString
"detail" ((Object -> Parser ImageLoadEvent)
 -> Value -> Parser ImageLoadEvent)
-> (Object -> Parser ImageLoadEvent)
-> Value
-> Parser ImageLoadEvent
forall a b. (a -> b) -> a -> b
$ \Object
o ->
      Int -> Int -> ImageLoadEvent
ImageLoadEvent
        (Int -> Int -> ImageLoadEvent)
-> Parser Int -> Parser (Int -> ImageLoadEvent)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> MisoString -> Parser Int
forall a. FromJSON a => Object -> MisoString -> Parser a
.: MisoString
"width"
        Parser (Int -> ImageLoadEvent)
-> Parser Int -> Parser ImageLoadEvent
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 -> MisoString -> Parser Int
forall a. FromJSON a => Object -> MisoString -> Parser a
.: MisoString
"height"
-----------------------------------------------------------------------------
imageErrorDecoder :: Decoder ImageErrorEvent
imageErrorDecoder :: Decoder ImageErrorEvent
imageErrorDecoder = [MisoString
"detail"] [MisoString]
-> (Value -> Parser ImageErrorEvent) -> Decoder ImageErrorEvent
forall a. [MisoString] -> (Value -> Parser a) -> Decoder a
`at` Value -> Parser ImageErrorEvent
details
  where
    details :: Value -> Parser ImageErrorEvent
details = MisoString
-> (Object -> Parser ImageErrorEvent)
-> Value
-> Parser ImageErrorEvent
forall a. MisoString -> (Object -> Parser a) -> Value -> Parser a
withObject MisoString
"detail" ((Object -> Parser ImageErrorEvent)
 -> Value -> Parser ImageErrorEvent)
-> (Object -> Parser ImageErrorEvent)
-> Value
-> Parser ImageErrorEvent
forall a b. (a -> b) -> a -> b
$ \Object
o ->
      MisoString -> Int -> Int -> ImageErrorEvent
ImageErrorEvent
        (MisoString -> Int -> Int -> ImageErrorEvent)
-> Parser MisoString -> Parser (Int -> Int -> ImageErrorEvent)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> MisoString -> Parser MisoString
forall a. FromJSON a => Object -> MisoString -> Parser a
.: MisoString
"errMsg"
        Parser (Int -> Int -> ImageErrorEvent)
-> Parser Int -> Parser (Int -> ImageErrorEvent)
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 -> MisoString -> Parser Int
forall a. FromJSON a => Object -> MisoString -> Parser a
.: MisoString
"error_code"
        Parser (Int -> ImageErrorEvent)
-> Parser Int -> Parser ImageErrorEvent
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 -> MisoString -> Parser Int
forall a. FromJSON a => Object -> MisoString -> Parser a
.: MisoString
"lynx_categorized_code"
-----------------------------------------------------------------------------

-----------------------------------------------------------------------------
-- | Like 'onLoad', but the handler also receives the target element's 'DOMRef'.
-- Use for main-thread ('MTS') handlers that imperatively mutate the element.
onLoadWith :: (ImageLoadEvent -> DOMRef -> action) -> Attribute model action
onLoadWith :: forall action model.
(ImageLoadEvent -> DOMRef -> action) -> Attribute model action
onLoadWith ImageLoadEvent -> DOMRef -> action
action = MisoString
-> Decoder ImageLoadEvent
-> (ImageLoadEvent -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"load" Decoder ImageLoadEvent
imageLoadDecoder ((ImageLoadEvent -> model -> DOMRef -> action)
 -> Attribute model action)
-> (ImageLoadEvent -> model -> DOMRef -> action)
-> Attribute model action
forall a b. (a -> b) -> a -> b
$ \ImageLoadEvent
x model
_ DOMRef
domRef -> ImageLoadEvent -> DOMRef -> action
action ImageLoadEvent
x DOMRef
domRef
-----------------------------------------------------------------------------
-- | Like 'onError', but the handler also receives the target element's 'DOMRef'.
-- Use for main-thread ('MTS') handlers that imperatively mutate the element.
onErrorWith :: (ImageErrorEvent -> DOMRef -> action) -> Attribute model action
onErrorWith :: forall action model.
(ImageErrorEvent -> DOMRef -> action) -> Attribute model action
onErrorWith ImageErrorEvent -> DOMRef -> action
action = MisoString
-> Decoder ImageErrorEvent
-> (ImageErrorEvent -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"error" Decoder ImageErrorEvent
imageErrorDecoder ((ImageErrorEvent -> model -> DOMRef -> action)
 -> Attribute model action)
-> (ImageErrorEvent -> model -> DOMRef -> action)
-> Attribute model action
forall a b. (a -> b) -> a -> b
$ \ImageErrorEvent
x model
_ DOMRef
domRef -> ImageErrorEvent -> DOMRef -> action
action ImageErrorEvent
x DOMRef
domRef
-----------------------------------------------------------------------------
-- | Like 'onStartPlay', but the handler also receives the target element's 'DOMRef'.
-- Use for main-thread ('MTS') handlers that imperatively mutate the element.
onStartPlayWith :: (DOMRef -> action) -> Attribute model action
onStartPlayWith :: forall action model. (DOMRef -> action) -> Attribute model action
onStartPlayWith DOMRef -> action
action = MisoString
-> Decoder ()
-> (() -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"startplay" Decoder ()
emptyDecoder (\() model
_ DOMRef
ref -> DOMRef -> action
action DOMRef
ref)
-----------------------------------------------------------------------------
-- | Like 'onCurrentLoopComplete', but the handler also receives the target element's 'DOMRef'.
-- Use for main-thread ('MTS') handlers that imperatively mutate the element.
onCurrentLoopCompleteWith :: (DOMRef -> action) -> Attribute model action
onCurrentLoopCompleteWith :: forall action model. (DOMRef -> action) -> Attribute model action
onCurrentLoopCompleteWith DOMRef -> action
action = MisoString
-> Decoder ()
-> (() -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"currentloopcomplete" Decoder ()
emptyDecoder (\() model
_ DOMRef
ref -> DOMRef -> action
action DOMRef
ref)
-----------------------------------------------------------------------------
-- | Like 'onFinalLoopComplete', but the handler also receives the target element's 'DOMRef'.
-- Use for main-thread ('MTS') handlers that imperatively mutate the element.
onFinalLoopCompleteWith :: (DOMRef -> action) -> Attribute model action
onFinalLoopCompleteWith :: forall action model. (DOMRef -> action) -> Attribute model action
onFinalLoopCompleteWith DOMRef -> action
action = MisoString
-> Decoder ()
-> (() -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"finalloopcomplete" Decoder ()
emptyDecoder (\() model
_ DOMRef
ref -> DOMRef -> action
action DOMRef
ref)
-----------------------------------------------------------------------------