-----------------------------------------------------------------------------
{-# LANGUAGE OverloadedStrings #-}
-----------------------------------------------------------------------------
-- |
-- Module      :  Miso.Native.Element.ScrollView.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.ScrollView.Event
  ( -- *** Event
    onScroll
  , onScrollWith
  , onScrollMain
  , onScrollMainWith
  , onScrollToUpper
  , onScrollToUpperWith
  , onScrollToUpperMain
  , onScrollToUpperMainWith
  , onScrollToLower
  , onScrollToLowerWith
  , onScrollToLowerMain
  , onScrollToLowerMainWith
  , onScrollEnd
  , onScrollEndWith
  , onScrollEndMain
  , onScrollEndMainWith
  , onContentSizeChanged
  , onContentSizeChangedWith
  , onContentSizeChangedMain
  , onContentSizeChangedMainWith
  -- *** Decoders
  , scrollDecoder
  -- *** Types
  , ScrollEvent (..)
  -- *** Event Map
  , scrollViewEvents
  ) where
-----------------------------------------------------------------------------
import qualified Data.Map as M
-----------------------------------------------------------------------------
import           Miso.Types (Attribute, EventHandler, DOMRef)
import           Miso.Event
import           Miso.JSON (withObject, (.:?), (.!=))
import           Miso.String (MisoString)
-----------------------------------------------------------------------------
scrollViewEvents :: Events
scrollViewEvents :: Events
scrollViewEvents
  = [(MisoString, Phase)] -> Events
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList
  [ (MisoString
"scroll", Phase
BUBBLE)
  , (MisoString
"scrolltoupper", Phase
BUBBLE)
  , (MisoString
"scrolltolower", Phase
BUBBLE)
  , (MisoString
"scrollend", Phase
BUBBLE)
  , (MisoString
"contentsizechanged", Phase
BUBBLE)
  ]
-----------------------------------------------------------------------------
scrollDecoder :: Decoder ScrollEvent
scrollDecoder :: Decoder ScrollEvent
scrollDecoder = [MisoString
"detail"] [MisoString]
-> (Value -> Parser ScrollEvent) -> Decoder ScrollEvent
forall a. [MisoString] -> (Value -> Parser a) -> Decoder a
`at` do
  MisoString
-> (Object -> Parser ScrollEvent) -> Value -> Parser ScrollEvent
forall a. MisoString -> (Object -> Parser a) -> Value -> Parser a
withObject MisoString
"ScrollEvent" ((Object -> Parser ScrollEvent) -> Value -> Parser ScrollEvent)
-> (Object -> Parser ScrollEvent) -> Value -> Parser ScrollEvent
forall a b. (a -> b) -> a -> b
$ \Object
o ->
    MisoString
-> Double
-> Double
-> Double
-> Double
-> Double
-> Double
-> ScrollEvent
ScrollEvent
      -- @type@ is present on native scroll events but omitted by the web
      -- (LynxDevTool) preview; keep it optional so decoding succeeds in both.
      (MisoString
 -> Double
 -> Double
 -> Double
 -> Double
 -> Double
 -> Double
 -> ScrollEvent)
-> Parser MisoString
-> Parser
     (Double
      -> Double -> Double -> Double -> Double -> Double -> ScrollEvent)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> MisoString -> Parser (Maybe MisoString)
forall a. FromJSON a => Object -> MisoString -> Parser (Maybe a)
.:? MisoString
"type" Parser (Maybe MisoString) -> MisoString -> Parser MisoString
forall a. Parser (Maybe a) -> a -> Parser a
.!= MisoString
""
      Parser
  (Double
   -> Double -> Double -> Double -> Double -> Double -> ScrollEvent)
-> Parser Double
-> Parser
     (Double -> Double -> Double -> Double -> Double -> ScrollEvent)
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 (Maybe Double)
forall a. FromJSON a => Object -> MisoString -> Parser (Maybe a)
.:? MisoString
"deltaX" Parser (Maybe Double) -> Double -> Parser Double
forall a. Parser (Maybe a) -> a -> Parser a
.!= Double
0
      Parser
  (Double -> Double -> Double -> Double -> Double -> ScrollEvent)
-> Parser Double
-> Parser (Double -> Double -> Double -> Double -> ScrollEvent)
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 (Maybe Double)
forall a. FromJSON a => Object -> MisoString -> Parser (Maybe a)
.:? MisoString
"deltaY" Parser (Maybe Double) -> Double -> Parser Double
forall a. Parser (Maybe a) -> a -> Parser a
.!= Double
0
      Parser (Double -> Double -> Double -> Double -> ScrollEvent)
-> Parser Double
-> Parser (Double -> Double -> Double -> ScrollEvent)
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 (Maybe Double)
forall a. FromJSON a => Object -> MisoString -> Parser (Maybe a)
.:? MisoString
"scrollLeft" Parser (Maybe Double) -> Double -> Parser Double
forall a. Parser (Maybe a) -> a -> Parser a
.!= Double
0
      Parser (Double -> Double -> Double -> ScrollEvent)
-> Parser Double -> Parser (Double -> Double -> ScrollEvent)
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 (Maybe Double)
forall a. FromJSON a => Object -> MisoString -> Parser (Maybe a)
.:? MisoString
"scrollTop" Parser (Maybe Double) -> Double -> Parser Double
forall a. Parser (Maybe a) -> a -> Parser a
.!= Double
0
      Parser (Double -> Double -> ScrollEvent)
-> Parser Double -> Parser (Double -> ScrollEvent)
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 (Maybe Double)
forall a. FromJSON a => Object -> MisoString -> Parser (Maybe a)
.:? MisoString
"scrollHeight" Parser (Maybe Double) -> Double -> Parser Double
forall a. Parser (Maybe a) -> a -> Parser a
.!= Double
0
      Parser (Double -> ScrollEvent)
-> Parser Double -> Parser ScrollEvent
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 (Maybe Double)
forall a. FromJSON a => Object -> MisoString -> Parser (Maybe a)
.:? MisoString
"scrollWidth" Parser (Maybe Double) -> Double -> Parser Double
forall a. Parser (Maybe a) -> a -> Parser a
.!= Double
0
-----------------------------------------------------------------------------
data ScrollEvent
  = ScrollEvent
  { ScrollEvent -> MisoString
scrollType :: MisoString
  , ScrollEvent -> Double
deltaX, ScrollEvent -> Double
deltaY :: Double
  , ScrollEvent -> Double
scrollLeft, ScrollEvent -> Double
scrollTop, ScrollEvent -> Double
scrollHeight, ScrollEvent -> Double
scrollWidth :: Double
  } deriving (Int -> ScrollEvent -> ShowS
[ScrollEvent] -> ShowS
ScrollEvent -> String
(Int -> ScrollEvent -> ShowS)
-> (ScrollEvent -> String)
-> ([ScrollEvent] -> ShowS)
-> Show ScrollEvent
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ScrollEvent -> ShowS
showsPrec :: Int -> ScrollEvent -> ShowS
$cshow :: ScrollEvent -> String
show :: ScrollEvent -> String
$cshowList :: [ScrollEvent] -> ShowS
showList :: [ScrollEvent] -> ShowS
Show, ScrollEvent -> ScrollEvent -> Bool
(ScrollEvent -> ScrollEvent -> Bool)
-> (ScrollEvent -> ScrollEvent -> Bool) -> Eq ScrollEvent
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ScrollEvent -> ScrollEvent -> Bool
== :: ScrollEvent -> ScrollEvent -> Bool
$c/= :: ScrollEvent -> ScrollEvent -> Bool
/= :: ScrollEvent -> ScrollEvent -> Bool
Eq)
-----------------------------------------------------------------------------
-- | https://lynxjs.org/api/elements/built-in/scroll-view.html#scroll
--
-- @
--
-- data Action = HandleScroll ScrollEvent
--
-- view :: context -> props -> Model -> View context Action
-- view _ _ model = scrollView_ [ onScroll HandleScroll ] [ ]
--
-- update :: Action -> Effect props Model Action
-- update (HandleScroll ScrollEvent {..}) =
--   io_ (consoleLog "handled scroll event")
--
-- @
--
onScroll :: (ScrollEvent -> action) -> Attribute model action
onScroll :: forall action model.
(ScrollEvent -> action) -> Attribute model action
onScroll ScrollEvent -> action
action = MisoString
-> Decoder ScrollEvent
-> (ScrollEvent -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"scroll" Decoder ScrollEvent
scrollDecoder (\ScrollEvent
x model
_ DOMRef
_ -> ScrollEvent -> action
action ScrollEvent
x)
-----------------------------------------------------------------------------
-- | Like 'onScroll', but dispatched on the Lynx __main thread__ ('MTS').
--
-- Runs imperatively on the MTS (no VDOM diff). Meant to be used with
-- @-XStaticPointers@.
--
-- @
-- data Action = HandleScroll ScrollEvent
--
-- view_ [ event (static (onScrollMain HandleScroll)) ] [ "some view" ]
-- @
--
onScrollMain :: (ScrollEvent -> action) -> EventHandler model action
onScrollMain :: forall action model.
(ScrollEvent -> action) -> EventHandler model action
onScrollMain ScrollEvent -> action
action = MisoString
-> Decoder ScrollEvent
-> (ScrollEvent -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"scroll" Decoder ScrollEvent
scrollDecoder (\ScrollEvent
x model
_ DOMRef
_ -> ScrollEvent -> action
action ScrollEvent
x)
-----------------------------------------------------------------------------
-- | Like 'onScrollMain', but the handler also receives read-only access to the
-- @model@ and the target element's 'DOMRef' (for imperative MTS mutation).
--
-- @
-- data Action = HandleScroll ScrollEvent Model DOMRef
--
-- view_ [ event (static (onScrollMainWith HandleScroll)) ] [ "some view" ]
-- @
--
onScrollMainWith :: (ScrollEvent -> model -> DOMRef -> action) -> EventHandler model action
onScrollMainWith :: forall model action.
(ScrollEvent -> model -> DOMRef -> action)
-> EventHandler model action
onScrollMainWith ScrollEvent -> model -> DOMRef -> action
action = MisoString
-> Decoder ScrollEvent
-> (ScrollEvent -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"scroll" Decoder ScrollEvent
scrollDecoder ScrollEvent -> model -> DOMRef -> action
action
-----------------------------------------------------------------------------
-- | https://lynxjs.org/api/elements/built-in/scroll-view.html#scrolltoupper
--
-- @
--
-- data Action = HandleScroll ScrollEvent
--
-- view :: context -> props -> Model -> View context Action
-- view _ _ model = scrollView_ [ onScrollToUpper HnadleScroll ] [ ]
--
-- update :: Action -> Effect props Model Action
-- update (HandleScroll ScrollEvent {..}) =
--   io_ (consoleLog "handled scroll event")
--
-- @
--
onScrollToUpper :: (ScrollEvent -> action) -> Attribute model action
onScrollToUpper :: forall action model.
(ScrollEvent -> action) -> Attribute model action
onScrollToUpper ScrollEvent -> action
action = MisoString
-> Decoder ScrollEvent
-> (ScrollEvent -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"scrolltoupper" Decoder ScrollEvent
scrollDecoder (\ScrollEvent
x model
_ DOMRef
_ -> ScrollEvent -> action
action ScrollEvent
x)
-----------------------------------------------------------------------------
-- | Like 'onScrollToUpper', but dispatched on the Lynx __main thread__ ('MTS').
--
-- Runs imperatively on the MTS (no VDOM diff). Meant to be used with
-- @-XStaticPointers@.
--
-- @
-- data Action = HandleScroll ScrollEvent
--
-- view_ [ event (static (onScrollToUpperMain HandleScroll)) ] [ "some view" ]
-- @
--
onScrollToUpperMain :: (ScrollEvent -> action) -> EventHandler model action
onScrollToUpperMain :: forall action model.
(ScrollEvent -> action) -> EventHandler model action
onScrollToUpperMain ScrollEvent -> action
action = MisoString
-> Decoder ScrollEvent
-> (ScrollEvent -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"scrolltoupper" Decoder ScrollEvent
scrollDecoder (\ScrollEvent
x model
_ DOMRef
_ -> ScrollEvent -> action
action ScrollEvent
x)
-----------------------------------------------------------------------------
-- | Like 'onScrollToUpperMain', but the handler also receives read-only access
-- to the @model@ and the target element's 'DOMRef' (for imperative MTS mutation).
--
-- @
-- data Action = HandleScroll ScrollEvent Model DOMRef
--
-- view_ [ event (static (onScrollToUpperMainWith HandleScroll)) ] [ "some view" ]
-- @
--
onScrollToUpperMainWith :: (ScrollEvent -> model -> DOMRef -> action) -> EventHandler model action
onScrollToUpperMainWith :: forall model action.
(ScrollEvent -> model -> DOMRef -> action)
-> EventHandler model action
onScrollToUpperMainWith ScrollEvent -> model -> DOMRef -> action
action = MisoString
-> Decoder ScrollEvent
-> (ScrollEvent -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"scrolltoupper" Decoder ScrollEvent
scrollDecoder ScrollEvent -> model -> DOMRef -> action
action
-----------------------------------------------------------------------------
-- | https://lynxjs.org/api/elements/built-in/scroll-view.html#scrolltolower
--
-- @
--
-- data Action = HandleScroll ScrollEvent
--
-- view :: context -> props -> Model -> View context Action
-- view _ _ model = scrollView_ [ onScrollToLower HandleScroll ] [ ]
--
-- update :: Action -> Effect props Model Action
-- update (HandleScroll ScrollEvent {..}) =
--   io_ (consoleLog "handled scroll event")
--
-- @
--
onScrollToLower :: (ScrollEvent -> action) -> Attribute model action
onScrollToLower :: forall action model.
(ScrollEvent -> action) -> Attribute model action
onScrollToLower ScrollEvent -> action
action = MisoString
-> Decoder ScrollEvent
-> (ScrollEvent -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"scrolltolower" Decoder ScrollEvent
scrollDecoder (\ScrollEvent
x model
_ DOMRef
_ -> ScrollEvent -> action
action ScrollEvent
x)
-----------------------------------------------------------------------------
-- | Like 'onScrollToLower', but dispatched on the Lynx __main thread__ ('MTS').
--
-- Runs imperatively on the MTS (no VDOM diff). Meant to be used with
-- @-XStaticPointers@.
--
-- @
-- data Action = HandleScroll ScrollEvent
--
-- view_ [ event (static (onScrollToLowerMain HandleScroll)) ] [ "some view" ]
-- @
--
onScrollToLowerMain :: (ScrollEvent -> action) -> EventHandler model action
onScrollToLowerMain :: forall action model.
(ScrollEvent -> action) -> EventHandler model action
onScrollToLowerMain ScrollEvent -> action
action = MisoString
-> Decoder ScrollEvent
-> (ScrollEvent -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"scrolltolower" Decoder ScrollEvent
scrollDecoder (\ScrollEvent
x model
_ DOMRef
_ -> ScrollEvent -> action
action ScrollEvent
x)
-----------------------------------------------------------------------------
-- | Like 'onScrollToLowerMain', but the handler also receives read-only access
-- to the @model@ and the target element's 'DOMRef' (for imperative MTS mutation).
--
-- @
-- data Action = HandleScroll ScrollEvent Model DOMRef
--
-- view_ [ event (static (onScrollToLowerMainWith HandleScroll)) ] [ "some view" ]
-- @
--
onScrollToLowerMainWith :: (ScrollEvent -> model -> DOMRef -> action) -> EventHandler model action
onScrollToLowerMainWith :: forall model action.
(ScrollEvent -> model -> DOMRef -> action)
-> EventHandler model action
onScrollToLowerMainWith ScrollEvent -> model -> DOMRef -> action
action = MisoString
-> Decoder ScrollEvent
-> (ScrollEvent -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"scrolltolower" Decoder ScrollEvent
scrollDecoder ScrollEvent -> model -> DOMRef -> action
action
-----------------------------------------------------------------------------
-- | https://lynxjs.org/api/elements/built-in/scroll-view.html#scrollend
--
-- @
--
-- data Action = HandleScroll ScrollEvent
--
-- view :: context -> props -> Model -> View context Action
-- view _ _ model = scrollView_ [ onScrollToLower HandleScroll ] [ ]
--
-- update :: Action -> Effect props Model Action
-- update (HandleScroll ScrollEvent {..}) =
--   io_ (consoleLog "handled scroll event")
--
-- @
--
onScrollEnd :: (ScrollEvent -> action) -> Attribute model action
onScrollEnd :: forall action model.
(ScrollEvent -> action) -> Attribute model action
onScrollEnd ScrollEvent -> action
action = MisoString
-> Decoder ScrollEvent
-> (ScrollEvent -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"scrollend" Decoder ScrollEvent
scrollDecoder (\ScrollEvent
x model
_ DOMRef
_ -> ScrollEvent -> action
action ScrollEvent
x)
-----------------------------------------------------------------------------
-- | Like 'onScrollEnd', but dispatched on the Lynx __main thread__ ('MTS').
--
-- Runs imperatively on the MTS (no VDOM diff). Meant to be used with
-- @-XStaticPointers@.
--
-- @
-- data Action = HandleScroll ScrollEvent
--
-- view_ [ event (static (onScrollEndMain HandleScroll)) ] [ "some view" ]
-- @
--
onScrollEndMain :: (ScrollEvent -> action) -> EventHandler model action
onScrollEndMain :: forall action model.
(ScrollEvent -> action) -> EventHandler model action
onScrollEndMain ScrollEvent -> action
action = MisoString
-> Decoder ScrollEvent
-> (ScrollEvent -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"scrollend" Decoder ScrollEvent
scrollDecoder (\ScrollEvent
x model
_ DOMRef
_ -> ScrollEvent -> action
action ScrollEvent
x)
-----------------------------------------------------------------------------
-- | Like 'onScrollEndMain', but the handler also receives read-only access to
-- the @model@ and the target element's 'DOMRef' (for imperative MTS mutation).
--
-- @
-- data Action = HandleScroll ScrollEvent Model DOMRef
--
-- view_ [ event (static (onScrollEndMainWith HandleScroll)) ] [ "some view" ]
-- @
--
onScrollEndMainWith :: (ScrollEvent -> model -> DOMRef -> action) -> EventHandler model action
onScrollEndMainWith :: forall model action.
(ScrollEvent -> model -> DOMRef -> action)
-> EventHandler model action
onScrollEndMainWith ScrollEvent -> model -> DOMRef -> action
action = MisoString
-> Decoder ScrollEvent
-> (ScrollEvent -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"scrollend" Decoder ScrollEvent
scrollDecoder ScrollEvent -> model -> DOMRef -> action
action
-----------------------------------------------------------------------------
-- | https://lynxjs.org/api/elements/built-in/scroll-view.html#contentsizechanged
--
-- Triggered when the content area comprised of direct child nodes changes in width
-- or height. This event triggers after the \<scroll-view\> content completes layout.
-- If updating \<scroll-view\> child nodes, call updated scrolling methods like
-- `scrollTo` in this event.
--
-- @
--
-- data Action = HandleContentSizeChanged ScrollEvent
--
-- view :: context -> props -> Model -> View context Action
-- view _ _ model = scrollView_ [ onContentSizeChanged HandleContentSizeChanged ] [ ]
--
-- update :: Action -> Effect props Model Action
-- update (HandleContentSizeChanged ScrollEvent {..}) =
--   io_ (consoleLog "handled content size changed event")
--
-- @
--
onContentSizeChanged :: (ScrollEvent -> action) -> Attribute model action
onContentSizeChanged :: forall action model.
(ScrollEvent -> action) -> Attribute model action
onContentSizeChanged ScrollEvent -> action
action = MisoString
-> Decoder ScrollEvent
-> (ScrollEvent -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"contentsizechanged" Decoder ScrollEvent
scrollDecoder (\ScrollEvent
x model
_ DOMRef
_ -> ScrollEvent -> action
action ScrollEvent
x)
-----------------------------------------------------------------------------
-- | Like 'onContentSizeChanged', but dispatched on the Lynx __main thread__ ('MTS').
--
-- Runs imperatively on the MTS (no VDOM diff). Meant to be used with
-- @-XStaticPointers@.
--
-- @
-- data Action = HandleContentSizeChanged ScrollEvent
--
-- view_ [ event (static (onContentSizeChangedMain HandleContentSizeChanged)) ] [ "some view" ]
-- @
--
onContentSizeChangedMain :: (ScrollEvent -> action) -> EventHandler model action
onContentSizeChangedMain :: forall action model.
(ScrollEvent -> action) -> EventHandler model action
onContentSizeChangedMain ScrollEvent -> action
action = MisoString
-> Decoder ScrollEvent
-> (ScrollEvent -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"contentsizechanged" Decoder ScrollEvent
scrollDecoder (\ScrollEvent
x model
_ DOMRef
_ -> ScrollEvent -> action
action ScrollEvent
x)
-----------------------------------------------------------------------------
-- | Like 'onContentSizeChangedMain', but the handler also receives read-only
-- access to the @model@ and the target element's 'DOMRef' (for imperative MTS
-- mutation).
--
-- @
-- data Action = HandleContentSizeChanged ScrollEvent Model DOMRef
--
-- view_ [ event (static (onContentSizeChangedMainWith HandleContentSizeChanged)) ] [ "some view" ]
-- @
--
onContentSizeChangedMainWith :: (ScrollEvent -> model -> DOMRef -> action) -> EventHandler model action
onContentSizeChangedMainWith :: forall model action.
(ScrollEvent -> model -> DOMRef -> action)
-> EventHandler model action
onContentSizeChangedMainWith ScrollEvent -> model -> DOMRef -> action
action = MisoString
-> Decoder ScrollEvent
-> (ScrollEvent -> model -> DOMRef -> action)
-> EventHandler model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> EventHandler model action
onMain MisoString
"contentsizechanged" Decoder ScrollEvent
scrollDecoder ScrollEvent -> model -> DOMRef -> action
action
-----------------------------------------------------------------------------
-- | Like 'onScroll', but the handler also receives the target element's 'DOMRef'.
-- Use for main-thread ('MTS') handlers that imperatively mutate the element.
onScrollWith :: (ScrollEvent -> DOMRef -> action) -> Attribute model action
onScrollWith :: forall action model.
(ScrollEvent -> DOMRef -> action) -> Attribute model action
onScrollWith ScrollEvent -> DOMRef -> action
action = MisoString
-> Decoder ScrollEvent
-> (ScrollEvent -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"scroll" Decoder ScrollEvent
scrollDecoder ((ScrollEvent -> model -> DOMRef -> action)
 -> Attribute model action)
-> (ScrollEvent -> model -> DOMRef -> action)
-> Attribute model action
forall a b. (a -> b) -> a -> b
$ \ScrollEvent
se model
_ DOMRef
domRef -> ScrollEvent -> DOMRef -> action
action ScrollEvent
se DOMRef
domRef
-----------------------------------------------------------------------------
-- | Like 'onScrollToUpper', but the handler also receives the target element's 'DOMRef'.
-- Use for main-thread ('MTS') handlers that imperatively mutate the element.
onScrollToUpperWith :: (ScrollEvent -> DOMRef -> action) -> Attribute model action
onScrollToUpperWith :: forall action model.
(ScrollEvent -> DOMRef -> action) -> Attribute model action
onScrollToUpperWith ScrollEvent -> DOMRef -> action
action = MisoString
-> Decoder ScrollEvent
-> (ScrollEvent -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"scrolltoupper" Decoder ScrollEvent
scrollDecoder ((ScrollEvent -> model -> DOMRef -> action)
 -> Attribute model action)
-> (ScrollEvent -> model -> DOMRef -> action)
-> Attribute model action
forall a b. (a -> b) -> a -> b
$ \ScrollEvent
se model
_ DOMRef
domRef -> ScrollEvent -> DOMRef -> action
action ScrollEvent
se DOMRef
domRef
-----------------------------------------------------------------------------
-- | Like 'onScrollToLower', but the handler also receives the target element's 'DOMRef'.
-- Use for main-thread ('MTS') handlers that imperatively mutate the element.
onScrollToLowerWith :: (ScrollEvent -> DOMRef -> action) -> Attribute model action
onScrollToLowerWith :: forall action model.
(ScrollEvent -> DOMRef -> action) -> Attribute model action
onScrollToLowerWith ScrollEvent -> DOMRef -> action
action = MisoString
-> Decoder ScrollEvent
-> (ScrollEvent -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"scrolltolower" Decoder ScrollEvent
scrollDecoder ((ScrollEvent -> model -> DOMRef -> action)
 -> Attribute model action)
-> (ScrollEvent -> model -> DOMRef -> action)
-> Attribute model action
forall a b. (a -> b) -> a -> b
$ \ScrollEvent
se model
_ DOMRef
domRef -> ScrollEvent -> DOMRef -> action
action ScrollEvent
se DOMRef
domRef
-----------------------------------------------------------------------------
-- | Like 'onScrollEnd', but the handler also receives the target element's 'DOMRef'.
-- Use for main-thread ('MTS') handlers that imperatively mutate the element.
onScrollEndWith :: (ScrollEvent -> DOMRef -> action) -> Attribute model action
onScrollEndWith :: forall action model.
(ScrollEvent -> DOMRef -> action) -> Attribute model action
onScrollEndWith ScrollEvent -> DOMRef -> action
action = MisoString
-> Decoder ScrollEvent
-> (ScrollEvent -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"scrollend" Decoder ScrollEvent
scrollDecoder ((ScrollEvent -> model -> DOMRef -> action)
 -> Attribute model action)
-> (ScrollEvent -> model -> DOMRef -> action)
-> Attribute model action
forall a b. (a -> b) -> a -> b
$ \ScrollEvent
se model
_ DOMRef
domRef -> ScrollEvent -> DOMRef -> action
action ScrollEvent
se DOMRef
domRef
-----------------------------------------------------------------------------
-- | Like 'onContentSizeChanged', but the handler also receives the target element's 'DOMRef'.
-- Use for main-thread ('MTS') handlers that imperatively mutate the element.
onContentSizeChangedWith :: (ScrollEvent -> DOMRef -> action) -> Attribute model action
onContentSizeChangedWith :: forall action model.
(ScrollEvent -> DOMRef -> action) -> Attribute model action
onContentSizeChangedWith ScrollEvent -> DOMRef -> action
action = MisoString
-> Decoder ScrollEvent
-> (ScrollEvent -> model -> DOMRef -> action)
-> Attribute model action
forall result model action.
MisoString
-> Decoder result
-> (result -> model -> DOMRef -> action)
-> Attribute model action
on MisoString
"contentsizechanged" Decoder ScrollEvent
scrollDecoder ((ScrollEvent -> model -> DOMRef -> action)
 -> Attribute model action)
-> (ScrollEvent -> model -> DOMRef -> action)
-> Attribute model action
forall a b. (a -> b) -> a -> b
$ \ScrollEvent
se model
_ DOMRef
domRef -> ScrollEvent -> DOMRef -> action
action ScrollEvent
se DOMRef
domRef
-----------------------------------------------------------------------------