react-flux-1.0.2: A binding to React based on the Flux application architecture for GHCJS

Safe HaskellNone
LanguageHaskell2010

React.Flux.PropertiesAndEvents

Contents

Description

This module contains the definitions for creating properties to pass to javascript elements and foreign javascript classes. In addition, it contains definitions for the React Event System.

Synopsis

Documentation

data PropertyOrHandler handler Source

Either a property or an event handler.

The combination of all properties and event handlers are used to create the javascript object passed as the second argument to React.createElement.

Instances

Functor PropertyOrHandler Source 
(~) * child (ReactElementM eventHandler a) => Term eventHandler [PropertyOrHandler eventHandler] (child -> ReactElementM eventHandler a) Source 

Creating Properties

property :: ToJSVal val => String -> val -> PropertyOrHandler handler Source

Create a property from anything that can be converted to a JSVal

elementProperty :: String -> ReactElementM handler () -> PropertyOrHandler handler Source

Some third-party React classes allow passing React elements as properties. This function will first run the given ReactElementM to obtain an element or elements, and then use that element as the value for a property with the given key.

nestedProperty :: String -> [PropertyOrHandler handler] -> PropertyOrHandler handler Source

Allows you to create nested object properties. The list of properties passed in will be converted to an object which is then set as the value for a property with the given name. For example,

[ nestedProperty "Hello" [ "a" @= (100 :: Int), "b" $= "World" ]
, "c" $= "!!!"
]

would create a javascript object

{"Hello": {a: 100, b: "World"}, "c": "!!!"}

class CallbackFunction handler a | a -> handler Source

A class which is used to implement variable argument functions. Any function where each argument implements FromJSVal and the result is either ViewEventHandler or StatefulViewEventHandler is an instance of this class.

Minimal complete definition

applyFromArguments

callback :: CallbackFunction handler func => String -> func -> PropertyOrHandler handler Source

Create a callback property. This is primarily intended for foreign React classes which expect callbacks to be passed to them as properties. For events on DOM elements, you should instead use the handlers below.

The function func can be any function, as long as each argument to the function is an instance of FromJSVal and the result of the function is handler. Internally, callback creates a javascript function which accesses the arguments javascript object and then matches entries in arguments to the parameters of func. If func has more parameters than the javascript arguments object, a javascript null is used for the conversion. Since the Maybe instance of FromJSVal converts a null reference to Nothing, you can exploit this to create variable-argument javascript callbacks.

For example, all three of the following functions could be passed as func inside a view.

foo :: Int -> Maybe String -> ViewEventHandler
bar :: Aeson.Value -> ViewEventHandler
baz :: ViewEventHandler

For another example, see the haddock comments in React.Flux.Addons.Bootstrap.

Combinators

(@=) :: ToJSON a => Text -> a -> PropertyOrHandler handler Source

Create a property.

($=) :: Text -> Text -> PropertyOrHandler handler Source

Create a text-valued property. This is here to avoid problems when OverloadedStrings extension is enabled

classNames :: [(Text, Bool)] -> PropertyOrHandler handler Source

Set the className property to consist of all the names which are matched with True, allowing you to easily toggle class names based on a computation.

Creating Events

data Event Source

Every event in React is a synthetic event, a cross-browser wrapper around the native event.

Instances

newtype EventTarget Source

A reference to the object that dispatched the event. https://developer.mozilla.org/en-US/docs/Web/API/Event/target

Constructors

EventTarget JSVal 

eventTargetProp :: FromJSVal val => EventTarget -> String -> val Source

Access a property in an event target

target :: FromJSVal val => Event -> String -> val Source

A version of eventTargetProp which accesses the property of evtTarget in the event. This is useful for example:

div_ $
    input_ [ "type" @= "checked"
           , onChange $ \evt -> let val = target evt "value" in ...
           ]

In this case, val would coorespond to the javascript expression evt.target.value.

preventDefault :: Event -> SomeStoreAction Source

Prevent the default browser action from occuring in response to this event.

stopPropagation :: Event -> SomeStoreAction Source

Stop propagating this event, either down the DOM tree during the capture phase or up the DOM tree during the bubbling phase.

capturePhase :: PropertyOrHandler handler -> PropertyOrHandler handler Source

By default, the handlers below are triggered during the bubbling phase. Use this to switch them to trigger during the capture phase.

on :: String -> (Event -> handler) -> PropertyOrHandler handler Source

Use this to create an event handler for an event not covered by the rest of this module. At the moment, this is just the media events (onPlay, onPause, etc.) on image and video tags.

Keyboard

onKeyDown :: (Event -> KeyboardEvent -> handler) -> PropertyOrHandler handler Source

onKeyPress :: (Event -> KeyboardEvent -> handler) -> PropertyOrHandler handler Source

onKeyUp :: (Event -> KeyboardEvent -> handler) -> PropertyOrHandler handler Source

Focus

onBlur :: (Event -> FocusEvent -> handler) -> PropertyOrHandler handler Source

onFocus :: (Event -> FocusEvent -> handler) -> PropertyOrHandler handler Source

Form

onChange :: (Event -> handler) -> PropertyOrHandler handler Source

The onChange event is special in React and should be used for all input change events. For details, see https://facebook.github.io/react/docs/forms.html

onInput :: (Event -> handler) -> PropertyOrHandler handler Source

onSubmit :: (Event -> handler) -> PropertyOrHandler handler Source

Mouse

onClick :: (Event -> MouseEvent -> handler) -> PropertyOrHandler handler Source

onContextMenu :: (Event -> MouseEvent -> handler) -> PropertyOrHandler handler Source

onDoubleClick :: (Event -> MouseEvent -> handler) -> PropertyOrHandler handler Source

onDrag :: (Event -> MouseEvent -> handler) -> PropertyOrHandler handler Source

onDragEnd :: (Event -> MouseEvent -> handler) -> PropertyOrHandler handler Source

onDragEnter :: (Event -> MouseEvent -> handler) -> PropertyOrHandler handler Source

onDragExit :: (Event -> MouseEvent -> handler) -> PropertyOrHandler handler Source

onDragLeave :: (Event -> MouseEvent -> handler) -> PropertyOrHandler handler Source

onDragOver :: (Event -> MouseEvent -> handler) -> PropertyOrHandler handler Source

onDragStart :: (Event -> MouseEvent -> handler) -> PropertyOrHandler handler Source

onDrop :: (Event -> MouseEvent -> handler) -> PropertyOrHandler handler Source

onMouseDown :: (Event -> MouseEvent -> handler) -> PropertyOrHandler handler Source

onMouseEnter :: (Event -> MouseEvent -> handler) -> PropertyOrHandler handler Source

onMouseLeave :: (Event -> MouseEvent -> handler) -> PropertyOrHandler handler Source

onMouseMove :: (Event -> MouseEvent -> handler) -> PropertyOrHandler handler Source

onMouseOut :: (Event -> MouseEvent -> handler) -> PropertyOrHandler handler Source

onMouseOver :: (Event -> MouseEvent -> handler) -> PropertyOrHandler handler Source

onMouseUp :: (Event -> MouseEvent -> handler) -> PropertyOrHandler handler Source

Touch

initializeTouchEvents :: IO () Source

Initialize touch events is only needed with React 0.13, in version 0.14 it was removed.

onTouchCancel :: (Event -> TouchEvent -> handler) -> PropertyOrHandler handler Source

onTouchEnd :: (Event -> TouchEvent -> handler) -> PropertyOrHandler handler Source

onTouchMove :: (Event -> TouchEvent -> handler) -> PropertyOrHandler handler Source

onTouchStart :: (Event -> TouchEvent -> handler) -> PropertyOrHandler handler Source

UI

onScroll :: (Event -> handler) -> PropertyOrHandler handler Source

Wheel

onWheel :: (Event -> MouseEvent -> WheelEvent -> handler) -> PropertyOrHandler handler Source

Image

onLoad :: (Event -> handler) -> PropertyOrHandler handler Source

onError :: (Event -> handler) -> PropertyOrHandler handler Source