File tree Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -79,3 +79,11 @@ exports.renderToElementById = function(id) {
79
79
}
80
80
}
81
81
} ;
82
+
83
+ exports . createElement = function ( factory ) {
84
+ return function ( props ) {
85
+ return function ( children ) {
86
+ return React . createElement . apply ( React , [ factory , props ] . concat ( children ) ) ;
87
+ } ;
88
+ } ;
89
+ } ;
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ module React
22
22
, Render ()
23
23
24
24
, UISpec ()
25
+ , UIFactory ()
25
26
26
27
, Event ()
27
28
, MouseEvent ()
@@ -45,6 +46,7 @@ module React
45
46
, renderToString
46
47
, renderToBody
47
48
, renderToElementById
49
+ , createElement
48
50
) where
49
51
50
52
import Prelude
@@ -202,6 +204,9 @@ type UISpec props state eff =
202
204
) Unit
203
205
}
204
206
207
+ -- | Factory function for components.
208
+ type UIFactory props = props -> UI
209
+
205
210
-- | Create a component specification.
206
211
spec :: forall props state eff . state -> Render props state eff -> UISpec props state eff
207
212
spec st render =
@@ -250,8 +255,7 @@ transformState ctx f = do
250
255
-- | Create a component from a component spec.
251
256
foreign import mkUI :: forall props state eff .
252
257
UISpec props state eff ->
253
- props ->
254
- UI
258
+ UIFactory props
255
259
256
260
-- | Create an event handler.
257
261
foreign import handle :: forall eff ev props state result .
@@ -266,3 +270,6 @@ foreign import renderToBody :: forall eff. UI -> Eff (dom :: DOM | eff) UI
266
270
267
271
-- | Render a component to the element with the specified ID.
268
272
foreign import renderToElementById :: forall eff . String -> UI -> Eff (dom :: DOM | eff ) UI
273
+
274
+ -- | Create an element from a component factory.
275
+ foreign import createElement :: forall props . UIFactory props -> props -> Array UI -> UI
You can’t perform that action at this time.
0 commit comments