Skip to content

Commit ffb8e61

Browse files
committed
Merge pull request #54 from ethul/topic/dynamic-children
Topic/dynamic children
2 parents 12f9412 + f5f7c47 commit ffb8e61

File tree

18 files changed

+2457
-171
lines changed

18 files changed

+2457
-171
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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ 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+
- The first way is to spread the child element array when passing them to React's `createElement` function. The [React.DOM](docs/React/DOM.md) and [React.DOM.SVG](docs/React/DOM/SVG.md) spread the child element array.
16+
- The second way is to pass the child element array to `createElement` without spreading. This is useful when dealing with [dynamic children](https://facebook.github.io/react/docs/multiple-components.html#dynamic-children). In this case a `key` property should be assigned direclty to each child. The [React.DOM.Dynamic](docs/React/DOM/Dynamic.md) and [React.DOM.SVG.Dynamic](docs/React/DOM/SVG/Dynamic.md) pass the child element array without spreading.
17+
18+
Note that this module provides functions `createElement` and `createElementDynamic` to handle the two cases above for component classes.
19+
1220
## Building
1321

1422
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: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
## Module React.DOM
22

3+
#### `IsDynamic`
4+
5+
``` purescript
6+
newtype IsDynamic
7+
= IsDynamic Boolean
8+
```
9+
310
#### `mkDOM`
411

512
``` purescript
6-
mkDOM :: String -> Array Props -> Array ReactElement -> ReactElement
13+
mkDOM :: IsDynamic -> TagName -> Array Props -> Array ReactElement -> ReactElement
714
```
815

916
#### `text`

0 commit comments

Comments
 (0)