module React.Types where
import Control.Applicative
import Control.DeepSeq
import Control.Monad
import qualified Data.Aeson as Aeson
import Data.List (partition)
import Data.Maybe
import Data.Monoid
import Data.String
import Data.Text (Text)
import React.GHCJS
import React.Imports
import React.Registry
instance Show JSString where
show = fromJSString
type JSON = Aeson.Value
data EvtType
= ChangeEvt
| BlurEvt
| FocusEvt
| KeyDownEvt
| KeyPressEvt
| KeyUpEvt
| ClickEvt
| DoubleClickEvt
| MouseEnterEvt
| MouseLeaveEvt
data EventHandler signal = EventHandler
{ handler :: RawEvent -> Maybe signal
, evtType :: EvtType
}
data ReactClass props state insig exsig ctx = ReactClass
{ classForeign :: JSAny
, classTransition :: (state, insig) -> (state, Maybe exsig)
, classStateRegistry :: ClassRegistry props state insig exsig
}
data ReactNode sig
= ComponentElement (ReactComponentElement sig)
| DomElement (ReactDOMElement sig)
| forall props. ToJSRef props =>
ForeignClass (ImportedClass props sig) props (ReactNode sig)
| NodeText Text
| NodeSequence [ReactNode sig]
| forall insig. LocalNode (insig -> sig) (ReactNode insig)
instance Monoid (ReactNode sig) where
mempty = NodeSequence []
(NodeSequence xs) `mappend` (NodeSequence ys) = NodeSequence (xs <> ys)
(NodeSequence xs) `mappend` y = NodeSequence (xs <> [y])
x `mappend` (NodeSequence ys) = NodeSequence (x : ys)
x `mappend` y = NodeSequence [x, y]
instance IsString (ReactNode sig) where
fromString str = NodeText (fromString str)
data AttrOrHandler signal
= StaticAttr Text JSON
| Handler (EventHandler signal)
data ReactComponentElement exsig = forall props state insig ctx.
ReactComponentElement
{ reComType :: ReactClass props state insig exsig ctx
, reComChildren :: ReactNode insig
, reComKey :: Maybe JSString
, reComRef :: Maybe JSString
, reComProps :: props
}
data ReactDOMElement sig = ReactDOMElement
{ reDomType :: JSString
, reDomProps :: [AttrOrHandler sig]
, reDomChildren :: ReactNode sig
, reDomKey :: Maybe JSString
, reDomRef :: Maybe JSString
}