Skip to content

Topic/dynamic children #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
output
bower_components
node_modules
.pulp-cache/
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ For a more high-level set of bindings, you might like to look at `purescript-the

- [Module Documentation](docs/)

## Dynamic children

There are two ways that child elements can be passed to components:
- 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.
- 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.

Note that this module provides functions `createElement` and `createElementDynamic` to handle the two cases above for component classes.

## Building

The library and example can be built with Pulp as follows:
Expand Down
6 changes: 3 additions & 3 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
"test",
"tests"
],
"repository": {
"type": "git",
"repository": {
"type": "git",
"url": "git://github.com/purescript-contrib/purescript-react.git"
},
},
"dependencies": {
"purescript-dom": "~0.2.6"
},
Expand Down
34 changes: 33 additions & 1 deletion docs/React.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

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

#### `TagName`

``` purescript
type TagName = String
```

Name of a tag.

#### `ReactElement`

``` purescript
Expand Down Expand Up @@ -308,7 +316,31 @@ Create an event handler.
createElement :: forall props. ReactClass props -> props -> Array ReactElement -> ReactElement
```

Create an element from a React class.
Create an element from a React class spreading the children array. Used when the children are known up front.

#### `createElementDynamic`

``` purescript
createElementDynamic :: forall props. ReactClass props -> props -> Array ReactElement -> ReactElement
```

Create an element from a React class passing the children array. Used for a dynamic array of children.

#### `createElementTagName`

``` purescript
createElementTagName :: forall props. TagName -> props -> Array ReactElement -> ReactElement
```

Create an element from a tag name spreading the children array. Used when the children are known up front.

#### `createElementTagNameDynamic`

``` purescript
createElementTagNameDynamic :: forall props. TagName -> props -> Array ReactElement -> ReactElement
```

Create an element from a tag name passing the children array. Used for a dynamic array of children.

#### `createFactory`

Expand Down
9 changes: 8 additions & 1 deletion docs/React/DOM.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
## Module React.DOM

#### `IsDynamic`

``` purescript
newtype IsDynamic
= IsDynamic Boolean
```

#### `mkDOM`

``` purescript
mkDOM :: String -> Array Props -> Array ReactElement -> ReactElement
mkDOM :: IsDynamic -> TagName -> Array Props -> Array ReactElement -> ReactElement
```

#### `text`
Expand Down
Loading