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

 
Synopsis

Smart constructors

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

Convenience wrapper for onWithOptions defaultOptions.

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

onWithOptions :: Options -> MisoString -> Decoder r -> (r -> JSVal -> 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_ "+" ]

Lifecycle events

onMounted :: action -> Attribute action Source #

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

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

onMountedWith action is an event that gets called after the actual DOM element is created. It returns the component-id from the component. Returning component-id is useful when creating Component dynamically.

This way the parent can maintain a Map of the child Component IDs. When the parent Component wants to send a child Component a message it can use notify'.

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

onBeforeMounted :: action -> Attribute action Source #

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

onUnmounted :: action -> Attribute action Source #

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

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

onUnmounted action is an event that gets called after the DOM element is removed from the DOM. It returns the component-id after the unmount call. Returning component-id is useful when dynamically created Component need to notify their parents about their own destruction.

This way the parent can maintain a Map of the child Component IDs. When the parent Component wants to send a child Component a message it can use notify'.

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

onBeforeUnmounted :: action -> Attribute action Source #

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

onCreated :: action -> Attribute action Source #

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

onBeforeCreated :: action -> Attribute action Source #

onBeforeCreated action is an event that gets called before the DOM element is created on the DOM. The action is given the DOM element that was removed from the DOM tree.

onDestroyed :: action -> Attribute action Source #

onDestroyed action is an event that gets called after the DOM element is removed from the DOM. The action is given the DOM element that was removed from the DOM tree.

onBeforeDestroyed :: action -> Attribute action Source #

onBeforeDestroyed action is an event that gets called before the DOM element is removed from the DOM. The action is given the DOM element that was removed from the DOM tree.

Exports