Skip to content

Commit 2a6d564

Browse files
committed
Element creation and dynamic children
Allows for creating elements when the child elements are known up front and also when they are dynamic. Resolves #53
1 parent 12f9412 commit 2a6d564

File tree

19 files changed

+2338
-41
lines changed

19 files changed

+2338
-41
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
output
22
bower_components
33
node_modules
4+
.pulp-cache/

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,25 @@ For a more high-level set of bindings, you might like to look at `purescript-the
99

1010
- [Module Documentation](docs/)
1111

12+
## Dynamic children
13+
14+
There are two ways that child elements can be passed to components:
15+
1. The first way is to spread the child element array when passing
16+
them to React's `createElement` function.
17+
The [React.DOM](docs/React/DOM.md) and [React.DOM.SVG](docs/React/DOM/SVG.md)
18+
spread the child element array.
19+
2. The second way is to pass the child element array to `createElement`
20+
without spreading. This is useful when dealing with
21+
[dynamic children](https://facebook.github.io/react/docs/multiple-components.html#dynamic-children).
22+
In this case a `key` property should be assigned direclty to each child.
23+
The [React.DOM.Dynamic](docs/React/DOM/Dynamic.md) and
24+
[React.DOM.SVG.Dynamic](docs/React/DOM/SVG/Dynamic.md) pass the child
25+
element array without spreading.
26+
27+
Note that this module provides functions `createElement` and
28+
`createElementDynamic` to handle the two cases above for component
29+
classes.
30+
1231
## Building
1332

1433
The library and example can be built with Pulp as follows:

bower.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
"test",
1616
"tests"
1717
],
18-
"repository": {
19-
"type": "git",
18+
"repository": {
19+
"type": "git",
2020
"url": "git://github.com/purescript-contrib/purescript-react.git"
21-
},
21+
},
2222
"dependencies": {
2323
"purescript-dom": "~0.2.6"
2424
},

docs/React.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
This module defines foreign types and functions which wrap React's functionality.
44

5+
#### `TagName`
6+
7+
``` purescript
8+
type TagName = String
9+
```
10+
11+
Name of a tag.
12+
513
#### `ReactElement`
614

715
``` purescript
@@ -308,7 +316,31 @@ Create an event handler.
308316
createElement :: forall props. ReactClass props -> props -> Array ReactElement -> ReactElement
309317
```
310318

311-
Create an element from a React class.
319+
Create an element from a React class spreading the children array. Used when the children are known up front.
320+
321+
#### `createElementDynamic`
322+
323+
``` purescript
324+
createElementDynamic :: forall props. ReactClass props -> props -> Array ReactElement -> ReactElement
325+
```
326+
327+
Create an element from a React class passing the children array. Used for a dynamic array of children.
328+
329+
#### `createElementTagName`
330+
331+
``` purescript
332+
createElementTagName :: forall props. TagName -> props -> Array ReactElement -> ReactElement
333+
```
334+
335+
Create an element from a tag name spreading the children array. Used when the children are known up front.
336+
337+
#### `createElementTagNameDynamic`
338+
339+
``` purescript
340+
createElementTagNameDynamic :: forall props. TagName -> props -> Array ReactElement -> ReactElement
341+
```
342+
343+
Create an element from a tag name passing the children array. Used for a dynamic array of children.
312344

313345
#### `createFactory`
314346

docs/React/DOM.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#### `mkDOM`
44

55
``` purescript
6-
mkDOM :: String -> Array Props -> Array ReactElement -> ReactElement
6+
mkDOM :: TagName -> Array Props -> Array ReactElement -> ReactElement
77
```
88

99
#### `text`

0 commit comments

Comments
 (0)