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

Miso.Event

Description

Functions for specifying component lifecycle events and event handlers in View.

Synopsis

Smart constructors

on :: MisoString -> Decoder r -> (r -> DOMRef -> action) -> Attribute action Source #

Convenience wrapper for onWithOptions defaultOptions.

let clickHandler = on "click" emptyDecoder $ \() -> Action
in button_ [ clickHandler, class_ "add" ] [ text_ "+" ]

This is used to define events that are triggered during the browser bubble phase.

onCapture :: MisoString -> Decoder r -> (r -> DOMRef -> action) -> Attribute action Source #

Convenience wrapper for onWithOptions (True :: Capture).

let clickHandler = onCapture "click" emptyDecoder $ \() -> Action
in button_ [ clickHandler, class_ "add" ] [ text_ "+" ]

This is used to define events that are triggered during the browser capture phase.

onWithOptions :: Phase -> Options -> MisoString -> Decoder r -> (r -> DOMRef -> action) -> Attribute action Source #

onWithOptions opts eventName decoder toAction is an attribute that will set the event handler of the associated DOM node to a function that decodes its argument using decoder, converts it to an action using toAction and then feeds that action back to the update function.

opts can be used to disable further event propagation.

let clickHandler = onWithOptions defaultOptions "click" emptyDecoder $ \() -> Action
in button_ [ clickHandler, class_ "add" ] [ text_ "+" ]

data Phase Source #

Phase during which event listener is invoked.

Since: 1.9.0.0

Constructors

CAPTURE 
BUBBLE 

Instances

Instances details
Show Phase Source # 
Instance details

Defined in Miso.Event.Types

Methods

showsPrec :: Int -> Phase -> ShowS #

show :: Phase -> String #

showList :: [Phase] -> ShowS #

Eq Phase Source # 
Instance details

Defined in Miso.Event.Types

Methods

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

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

ToJSVal Phase Source # 
Instance details

Defined in Miso.Event.Types

Lifecycle events

onMounted :: action -> Attribute action Source #

onMounted action is an event that gets called after the actual DOM element is created.

Since: 1.9.0.0

onMountedWith :: (DOMRef -> action) -> Attribute action Source #

onMountedWith action is an event that gets called after the actual DOM element is created. It returns the componentId from the component. Passes the DOMRef to the action.

Use this or onMounted, but not both in the same [Attribute action] list.

Since: 1.9.0.0

onBeforeMounted :: action -> Attribute action Source #

onBeforeMounted action is an event that gets called before the actual DOM element is created.

Since: 1.9.0.0

onUnmounted :: action -> Attribute action Source #

onUnmounted action is an event that gets called after the DOM element is removed from the DOM.

Since: 1.9.0.0

onUnmountedWith :: (DOMRef -> action) -> Attribute action Source #

onUnmountedWith action is an event that gets called after the DOM element is removed from the DOM. Passes the DOMRef to the action.

Use this or onUnmounted, but not both in the same [Attribute action] list.

Since: 1.9.0.0

onBeforeUnmounted :: action -> Attribute action Source #

onBeforeUnmounted action is an event that gets called before the DOM element is removed from the DOM.

Since: 1.9.0.0

onBeforeUnmountedWith :: (DOMRef -> action) -> Attribute action Source #

onBeforeUnmountedWith is an event that gets called before the Component unmounts and before the DOM element is removed from the DOM.

Since: 1.9.0.0

onCreated :: action -> Attribute action Source #

onCreated action is an event that gets called after the actual DOM element is created.

Since: 1.9.0.0

onCreatedWith :: (DOMRef -> action) -> Attribute action Source #

Like onCreated action but passes along the DOMRef

Since: 1.9.0.0

onBeforeCreated :: action -> Attribute action Source #

onBeforeCreated action is an event that gets called before the DOM element is created on the DOM.

Since: 1.9.0.0

onDestroyed :: action -> Attribute action Source #

onDestroyed action is an event that gets called after the DOM element is removed from the DOM.

Since: 1.9.0.0

onBeforeDestroyed :: action -> Attribute action Source #

onBeforeDestroyed action is an event that gets called before the DOM element is removed from the DOM.

Since: 1.9.0.0

onBeforeDestroyedWith :: (DOMRef -> action) -> Attribute action Source #

Like onBeforeDestroyed but passes along the DOMRef

Since: 1.9.0.0

Exports