react-haskell-2.0.0: Haskell React bindings

Safe HaskellNone
LanguageHaskell2010

React

Contents

Synopsis

Classes

data ReactClass props state insig exsig ctx Source

A ReactClass is a standalone component of a user interface which contains the state necessary to render itself. Classes are a tool for scoping.

Use createClass to construct.

data ClassConfig props state insig exsig ctx Source

Constructors

ClassConfig 

Fields

renderFn :: props -> state -> ReactNode insig
 
initialState :: state
 
name :: JSString
 
transition :: (state, insig) -> (state, Maybe exsig)
 
startupSignals :: [insig]
 
childContext :: Maybe (HashMap Text ctx)
 

smartClass :: ClassConfig props state insig exsig JSString Source

dumbClass :: ClassConfig props () sig sig JSString Source

Rendering

debugRender :: Show sig => ReactNode sig -> Element -> IO () Source

React Nodes

data ReactNode sig Source

Instances

Events

data EventProperties e Source

Low level properties common to all events

Instances

data Target Source

Constructors

Target 

Fields

value :: !JSString
 
tagName :: !JSString
 

Native Events

Synthetic Events

Local

class GeneralizeSignal sigloc siggen where Source

Implement when a local signal can be generalized to a higher level one. Used by locally

Methods

generalizeSignal :: sigloc -> siggen Source

locally :: GeneralizeSignal sigloc siggen => ReactNode sigloc -> ReactNode siggen Source

locally exists to make it simple to embed classes with local concerns. An example will be helpful:

We have some page which can respond to many different events.

data Transition
    = UserTyping JSString
    | Toggle
    ...

globalPage_ :: [AttrOrHandler Transition] -> ReactNode Transition

And we want to be able to embed some components that don't care about all that. inputBox_ can only output JSString and pageHeader_ can't send any signals at all.

inputBox_ :: ReactNode JSString
pageHeader_ :: ReactNode Void

With locally we can easily embed them in globalPage_:

instance GeneralizeSignal JSString Transition where
    generalizeSignal = UserTyping

-- (globalPage_)
renderFn = props state -> div_ [ class_ "global-page" ] $ do
    locally pageHeader_
    ...
    locally inputBox_
    ...

data AttrOrHandler signal Source

Attributes

newtype NoProps Source

When importing a foreign class you must specify the props it takes. In the common case where it takes no props, only handles layout, it's convenient to specify the type of props as NoProps.

Example:

pageLayout_ :: ReactNode () -> ReactNode () pageLayout_ = importParentClass pageLayout noProps

Constructors

NoProps () 

Instances

noProps :: NoProps Source

Used when importing a foreign class taking no props. See above example.

Creating Elements

Class creation

classParent :: ClassCtx ctx => ClassConfig props state insig exsig ctx -> ReactNode insig -> props -> ReactNode exsig Source

classLeaf :: ClassCtx ctx => ClassConfig props state insig exsig ctx -> props -> ReactNode exsig Source

JS Interop

exportClassLeaf :: ClassCtx ctx => ClassConfig props state insig exsig ctx -> ExportedClass Source

importLeafClass :: ToJSRef props => ImportedClass props sig -> props -> ReactNode sig Source

importParentClass :: ToJSRef props => ImportedClass props sig -> props -> ReactNode sig -> ReactNode sig Source

data ExportedNode sig Source

Instances

type ExportedClass = JSRef ExportedClass_ Source

JS Interop

type ImportedClass props sig = JSRef (ImportedClass_ props sig) Source