glazier-react-0.5.0.0: ReactJS binding using Glazier and Pipes.Fluid

Safe HaskellNone
LanguageHaskell2010

Glazier.React.Event

Description

This module based on ReactFluxPropertiesAndEvents.hs.

Synopsis

Documentation

data SyntheticEvent Source #

Every event in React is a synthetic event, a cross-browser wrapper around the native event. SyntheticEvent must only be used in the first part of eventHandler.

eventHandler :: NFData a => (evt -> a) -> (a -> b) -> evt -> b Source #

Using the NFData idea from ReactFluxPropertiesAndEvents.hs React re-uses SyntheticEvent from a pool, which means it may no longer be valid if we lazily parse it. However, we still want lazy parsing so we don't parse unnecessary fields. Additionally, we don't want to block during the event handling.The reason this is a problem is because Javascript is single threaded, but Haskell is lazy. Therefore GHCJS threads are a strange mixture of synchronous and asynchronous threads, where a synchronous thread might be converted to an asynchronous thread if a "black hole" is encountered. See https://github.com/ghcjs/ghcjs-base/blob/master/GHCJS/Concurrent.hs This safe interface requires two input functions: 1. a function to reduce SyntheticEvent to a NFData. The mkEventCallback will ensure that the NFData is forced which will ensure all the required fields from Synthetic event has been parsed. This function must not block. 2. a second function that uses the NFData. This function is allowed to block. mkEventHandler results in a function that you can safely pass into syncCallback1 with ContinueAsync.

eventHandlerM :: (Monad m, NFData a) => (evt -> m a) -> (a -> m b) -> evt -> m b Source #

a monadic version of eventHandler The monad's effects must not block!

data Event Source #

Every SyntheticEvent can be parsed to an Event. Event must only be used in the first part of eventHandler.

data MouseEvent Source #

Mouse and Drag/Drop events MouseEvent must only be used in the first part of eventHandler. https://facebook.github.io/react/docs/events.html#mouse-events https://developer.mozilla.org/en-US/docs/Web/Events Event names (eventType) onClick (click) onContextMenu (contextmenu) onDoubleClick (dblclick) onDrag (drag) onDragEnd (dragend) onDragEnter (dragenter) onDragExit (dragexit) onDragLeave (dragleave) onDragOver (dragover) onDragStart (dragstart) onDrop (drop) onMouseDown (mousedown) onMouseEnter (mouseenter) onMouseLeave (mouseleave) onMouseMove (mousemove) onMouseOut (mouseout) onMouseOver (mouseover) onMouseUp (mouseup)

parseMouseEvent :: SyntheticEvent -> IO (Maybe MouseEvent) Source #

We can lie about this not being in IO because within the strict part of eventHandlerM the SyntheticEvent is effectively immutable.

data KeyboardEvent Source #

Keyboard events KeyboardEvent must only be used in the first part of eventHandler. https://facebook.github.io/react/docs/events.html#keyboard-events Event names (eventType) onKeyDown (keydown) onKeyPress (keypress) onKeyUp (keyyp)

parseKeyboardEvent :: SyntheticEvent -> IO (Maybe KeyboardEvent) Source #

We can lie about this not being in IO because within the strict part of eventHandlerM the SyntheticEvent is effectively immutable.