Skip to content

Latest commit

 

History

History
558 lines (325 loc) · 9.63 KB

Halogen-Events.md

File metadata and controls

558 lines (325 loc) · 9.63 KB

Module Documentation

Module Halogen.HTML.Events.Types

This module defines types for common DOM events

Event

type Event fields = { "type" :: String, timeStamp :: Number, target :: HTMLElement, currentTarget :: HTMLElement, cancelable :: Boolean, bubbles :: Boolean | fields }

This record synonym captures the properties which appear on every DOM event.

The fields type parameter allows us to attach different types of additional properties to represent more specific types of events.

MouseEvent

type MouseEvent = (which :: Number, metaKey :: Boolean, altKey :: Boolean, shiftKey :: Boolean, ctrlKey :: Boolean, screenY :: Number, screenX :: Number, clientY :: Number, clientX :: Number, relatedTarget :: HTMLElement, detail :: Number, button :: Number)

Identifies the additional fields which are available on mouse events.

KeyboardEvent

type KeyboardEvent = (which :: Number, metaKey :: Boolean, altKey :: Boolean, shiftKey :: Boolean, ctrlKey :: Boolean, keyCode :: Number, charCode :: Number)

Identifies the additional fields which are available on keyboard events.

FocusEvent

type FocusEvent = (relatedTarget :: HTMLElement)

Identifies the additional fields which are available on focus events.

Module Halogen.HTML.Events

This module defines well-typed wrappers for common DOM events, so that they may be safely embedded in HTML documents.

input

input :: forall i m a. (Applicative m) => (a -> i) -> a -> EventHandler (m i)

A helper function which can be used to create simple event handlers.

Often we don't need to use EventHandler or the monad underlying our component, and just need to generate an input to the signal function.

This function provides an alternative to making two nested calls to pure:

onClick (input \_ -> Input)

input_

input_ :: forall i m a. (Applicative m) => i -> a -> EventHandler (m i)

A helper function for simple event handlers that provide an input to the signal function, where there is no need to make use of the event value to generate the input.

onclick (input_ Input)

onAbort

onAbort :: forall i. (Event () -> EventHandler i) -> H.Attr i

onBeforeUnload

onBeforeUnload :: forall i. (Event () -> EventHandler i) -> H.Attr i

onError

onError :: forall i. (Event () -> EventHandler i) -> H.Attr i

onHashChange

onHashChange :: forall i. (Event () -> EventHandler i) -> H.Attr i

onLoad

onLoad :: forall i. (Event () -> EventHandler i) -> H.Attr i

onPageShow

onPageShow :: forall i. (Event () -> EventHandler i) -> H.Attr i

onPageHide

onPageHide :: forall i. (Event () -> EventHandler i) -> H.Attr i

onResize

onResize :: forall i. (Event () -> EventHandler i) -> H.Attr i

onScroll

onScroll :: forall i. (Event () -> EventHandler i) -> H.Attr i

onUnload

onUnload :: forall i. (Event () -> EventHandler i) -> H.Attr i

onChange

onChange :: forall i. (Event () -> EventHandler i) -> H.Attr i

onInvalid

onInvalid :: forall i. (Event () -> EventHandler i) -> H.Attr i

onReset

onReset :: forall i. (Event () -> EventHandler i) -> H.Attr i

onSearch

onSearch :: forall i. (Event () -> EventHandler i) -> H.Attr i

onSelect

onSelect :: forall i. (Event () -> EventHandler i) -> H.Attr i

onSubmit

onSubmit :: forall i. (Event () -> EventHandler i) -> H.Attr i

onClick

onClick :: forall i. (Event MouseEvent -> EventHandler i) -> H.Attr i

onContextMenu

onContextMenu :: forall i. (Event MouseEvent -> EventHandler i) -> H.Attr i

onDoubleClick

onDoubleClick :: forall i. (Event MouseEvent -> EventHandler i) -> H.Attr i

onMouseDown

onMouseDown :: forall i. (Event MouseEvent -> EventHandler i) -> H.Attr i

onMouseEnter

onMouseEnter :: forall i. (Event MouseEvent -> EventHandler i) -> H.Attr i

onMouseLeave

onMouseLeave :: forall i. (Event MouseEvent -> EventHandler i) -> H.Attr i

onMouseMove

onMouseMove :: forall i. (Event MouseEvent -> EventHandler i) -> H.Attr i

onMouseOver

onMouseOver :: forall i. (Event MouseEvent -> EventHandler i) -> H.Attr i

onMouseOut

onMouseOut :: forall i. (Event MouseEvent -> EventHandler i) -> H.Attr i

onMouseUp

onMouseUp :: forall i. (Event MouseEvent -> EventHandler i) -> H.Attr i

onKeyDown

onKeyDown :: forall i. (Event KeyboardEvent -> EventHandler i) -> H.Attr i

onKeyPress

onKeyPress :: forall i. (Event KeyboardEvent -> EventHandler i) -> H.Attr i

onKeyUp

onKeyUp :: forall i. (Event KeyboardEvent -> EventHandler i) -> H.Attr i

onBlur

onBlur :: forall i. (Event FocusEvent -> EventHandler i) -> H.Attr i

onFocus

onFocus :: forall i. (Event FocusEvent -> EventHandler i) -> H.Attr i

onFocusIn

onFocusIn :: forall i. (Event FocusEvent -> EventHandler i) -> H.Attr i

onFocusOut

onFocusOut :: forall i. (Event FocusEvent -> EventHandler i) -> H.Attr i

Module Halogen.HTML.Events.Handler

This module defines the EventHandler functor, which can be used to perform standard operations on HTML events.

EventHandler

newtype EventHandler a

This monad supports the following operations on events:

  • preventDefault
  • stopPropagation
  • stopImmediatePropagation

It can be used as follows:

import Control.Functor (($>))

H.a (E.onclick \_ -> E.preventDefault $> ClickHandler) (H.text "Click here")

preventDefault

preventDefault :: EventHandler Unit

Call the preventDefault method on the current event

stopPropagation

stopPropagation :: EventHandler Unit

Call the stopPropagation method on the current event

stopImmediatePropagation

stopImmediatePropagation :: EventHandler Unit

Call the stopImmediatePropagation method on the current event

functorEventHandler

instance functorEventHandler :: Functor EventHandler

applyEventHandler

instance applyEventHandler :: Apply EventHandler

applicativeEventHandler

instance applicativeEventHandler :: Applicative EventHandler

bindEventHandler

instance bindEventHandler :: Bind EventHandler

monadEventHandler

instance monadEventHandler :: Monad EventHandler

runEventHandler

runEventHandler :: forall a fields eff. Event fields -> EventHandler a -> Eff (dom :: DOM | eff) a

This function can be used to update an event and return the wrapped value

Module Halogen.HTML.Events.Monad

This module defines the Event monad.

Event

newtype Event eff a
  = Event (ListT (Aff eff) a)

The Event monad, which supports the asynchronous generation of events.

This monad is used in the definition of runUI.

unEvent

unEvent :: forall eff a. Event eff a -> ListT (Aff eff) a

Unwrap the Event constructor.

runEvent

runEvent :: forall eff a. (Error -> Eff eff Unit) -> (a -> Eff eff Unit) -> Event eff a -> Eff eff Unit

Run a computation in the Event monad by providing a callback function.

The callback function will be invoked zero or more times.

yield

yield :: forall eff a. a -> Event eff a

Yield an event. In practice, the event will be passed to the driver function.

async

async :: forall eff a. Aff eff a -> Event eff a

Lift an asynchronous computation into the Event monad.

andThen

andThen :: forall eff a. Event eff a -> (a -> Event eff a) -> Event eff a

A combinator which branches based on the supplied function after the first result, and returns to the original stream of events after the secondary stream has been exhausted.

semigroupEvent

instance semigroupEvent :: Semigroup (Event eff a)

monoidEvent

instance monoidEvent :: Monoid (Event eff a)

functorEvent

instance functorEvent :: Functor (Event eff)

applyEvent

instance applyEvent :: Apply (Event eff)

applicativeEvent

instance applicativeEvent :: Applicative (Event eff)

bindEvent

instance bindEvent :: Bind (Event eff)

monadEvent

instance monadEvent :: Monad (Event eff)

monadEffEvent

instance monadEffEvent :: MonadEff eff (Event eff)

monadAffEvent

instance monadAffEvent :: MonadAff eff (Event eff)

altEvent

instance altEvent :: Alt (Event eff)

plusEvent

instance plusEvent :: Plus (Event eff)

alternativeEvent

instance alternativeEvent :: Alternative (Event eff)

monadPlusEvent

instance monadPlusEvent :: MonadPlus (Event eff)