@@ -22,7 +22,7 @@ module React
2222 , Render ()
2323
2424 , UISpec ()
25- , UIFactory ()
25+ , UIClass ()
2626
2727 , Event ()
2828 , MouseEvent ()
@@ -44,18 +44,19 @@ module React
4444
4545 , handle
4646
47- , renderToString
48- , renderToBody
49- , renderToElementById
5047 , createElement
48+ , createFactory
49+
50+ , render
51+ , renderToString
5152 ) where
5253
53- import Prelude
54+ import Prelude ( Unit (), ($), bind , pure , return , unit )
5455
55- import DOM
56+ import DOM (DOM ())
57+ import DOM.Node.Types (Element ())
5658
57- import Control.Monad.Eff
58- import Control.Monad.Eff.Console
59+ import Control.Monad.Eff (Eff ())
5960
6061-- | A virtual DOM node, or component.
6162foreign import data UI :: *
@@ -212,13 +213,10 @@ type UISpec props state eff =
212213 ) Unit
213214 }
214215
215- -- | Factory function for components.
216- type UIFactory props = props -> UI
217-
218216-- | Create a component specification.
219217spec :: forall props state eff . state -> Render props state eff -> UISpec props state eff
220- spec st render =
221- { render: render
218+ spec st renderFn =
219+ { render: renderFn
222220 , displayName: " "
223221 , getInitialState: \_ -> pure st
224222 , componentWillMount: \_ -> return unit
@@ -230,6 +228,9 @@ spec st render =
230228 , componentWillUnmount: \_ -> return unit
231229 }
232230
231+ -- | Factory function for components.
232+ foreign import data UIClass :: * -> *
233+
233234-- | Read the component props.
234235foreign import getProps :: forall props eff .
235236 UIRef ->
@@ -265,24 +266,24 @@ transformState ctx f = do
265266 state <- readState ctx
266267 writeState ctx $ f state
267268
268- -- | Create a component from a component spec .
269+ -- | Create a React class from a specification .
269270foreign import mkUI :: forall props state eff .
270271 UISpec props state eff ->
271- UIFactory props
272+ UIClass props
272273
273274-- | Create an event handler.
274275foreign import handle :: forall eff ev props state result .
275276 (ev -> EventHandlerContext eff props state result ) ->
276277 EventHandler ev
277278
278- -- | Render a component as a string .
279- foreign import renderToString :: UI -> String
279+ -- | Render a React element in a document element .
280+ foreign import render :: forall eff . UI -> Element -> Eff ( dom :: DOM | eff ) UI
280281
281- -- | Render a component to the document body .
282- foreign import renderToBody :: forall eff . UI -> Eff ( dom :: DOM | eff ) UI
282+ -- | Render a React element as a string .
283+ foreign import renderToString :: UI -> String
283284
284- -- | Render a component to the element with the specified ID .
285- foreign import renderToElementById :: forall eff . String -> UI -> Eff ( dom :: DOM | eff ) UI
285+ -- | Create an element from a React class .
286+ foreign import createElement :: forall props . UIClass props -> props -> Array UI -> UI
286287
287- -- | Create an element from a component factory .
288- foreign import createElement :: forall props . UIFactory props -> props -> Array UI -> UI
288+ -- | Create a factory from a React class .
289+ foreign import createFactory :: forall props . UIClass props -> props -> UI
0 commit comments