-
Notifications
You must be signed in to change notification settings - Fork 39
Remove Array JSX
"children" argument
#15
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
77201da
Remove `Array JSX` "children" argument
maddie927 47f086e
Cleanup based on PR feedback
maddie927 a0742c7
Rebuild docs
maddie927 7a77a30
Alter createElementKeyed API, remove class polyfill
maddie927 6662afc
Rename stringComponent to unsafeCreateDOMComponent
maddie927 8e89c14
Fix readme
maddie927 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock.json binary |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,15 +4,15 @@ This package implements an opinionated set of bindings to the React library, opt | |
|
||
## Features | ||
|
||
- All React DOM elements and attributes are supported. | ||
- All React DOM elements and attributes are supported (soon, events are a work in progress). | ||
- An intuitive API for specifying props - no arrays of key value pairs, just records. | ||
- Attributes are optional, but type-checked. It is a type error to specify `href` as an integer, for example. | ||
|
||
## Getting Started | ||
|
||
You can install this package using Bower: | ||
|
||
``` | ||
```sh | ||
bower install [email protected]:lumihq/purescript-react-basic.git | ||
``` | ||
|
||
|
@@ -24,36 +24,32 @@ module React.Basic.Example where | |
import Prelude | ||
|
||
import Control.Monad.Eff.Uncurried (mkEffFn1) | ||
import React.Basic as R | ||
import React.Basic (ReactComponent, react) | ||
import React.Basic.DOM as R | ||
|
||
-- The props for the component | ||
type ExampleProps = | ||
{ label :: String | ||
} | ||
|
||
-- The internal state of the component | ||
type ExampleState = | ||
{ counter :: Int | ||
} | ||
|
||
-- Create a component by passing a record to the `react` function. | ||
-- The `render` function takes the props and current state, as well as a | ||
-- state update callback, and produces a document. | ||
example :: R.ReactComponent ExampleProps | ||
example = R.react | ||
example :: ReactComponent ExampleProps | ||
example = react | ||
{ initialState: { counter: 0 } | ||
, receiveProps: \_ _ _ -> pure unit | ||
, render: \{ label } { counter } setState -> | ||
R.button { onClick: mkEffFn1 \_ -> do | ||
setState { counter: counter + 1 } | ||
setState \s -> { counter: s.counter + 1 } | ||
, children: [ R.text (label <> ": " <> show counter) ] | ||
} | ||
[ R.text (label <> ": " <> show counter) ] | ||
} | ||
``` | ||
|
||
This component can be used directly from JavaScript. For example, if you are using `purs-loader`: | ||
|
||
```javascript | ||
```jsx | ||
import {example as Example} from 'React.Basic.Example.purs'; | ||
|
||
const myComponent = () => ( | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,19 @@ | ||
module Container where | ||
|
||
import Prelude | ||
|
||
import React.Basic as R | ||
import ToggleButton as ToggleButton | ||
|
||
component :: R.ReactComponent Unit | ||
component = R.react | ||
{ initialState: unit | ||
, receiveProps: \_ _ _ -> pure unit | ||
, render: \_ _ setState -> | ||
R.div { } [ R.component ToggleButton.component { on: true } | ||
, R.component ToggleButton.component { on: false } | ||
] | ||
} | ||
module Container where | ||
|
||
import Prelude | ||
|
||
import React.Basic (ReactComponent, createElement, react) | ||
import React.Basic.DOM as R | ||
import ToggleButton as ToggleButton | ||
|
||
component :: ReactComponent Unit | ||
component = react | ||
{ displayName: "Container" | ||
, initialState: unit | ||
, receiveProps: \_ _ _ -> pure unit | ||
, render: \_ _ setState -> | ||
R.div { children: [ createElement ToggleButton.component { on: true } | ||
, createElement ToggleButton.component { on: false } | ||
] | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,22 @@ | ||
module ToggleButton where | ||
|
||
import Prelude | ||
|
||
import Control.Monad.Eff.Uncurried (mkEffFn1) | ||
import React.Basic as R | ||
|
||
type ExampleProps = | ||
{ on :: Boolean | ||
} | ||
|
||
type ExampleState = | ||
{ on :: Boolean | ||
} | ||
|
||
component :: R.ReactComponent ExampleProps | ||
component = R.react | ||
{ initialState: { on: false } | ||
, receiveProps: \{ on } _ setState -> setState { on } | ||
, render: \_ { on } setState -> | ||
R.button { onClick: mkEffFn1 \_ -> setState { on: not on } | ||
} | ||
[ R.text if on then "On" else "Off" ] | ||
} | ||
module ToggleButton where | ||
|
||
import Prelude | ||
|
||
import Control.Monad.Eff.Uncurried (mkEffFn1) | ||
import React.Basic (ReactComponent, react) | ||
import React.Basic.DOM as R | ||
|
||
type ExampleProps = | ||
{ on :: Boolean | ||
} | ||
|
||
component :: ReactComponent ExampleProps | ||
component = react | ||
{ displayName: "ToggleButton" | ||
, initialState: { on: false } | ||
, receiveProps: \{ on } _ setState -> setState (const { on }) | ||
, render: \_ { on } setState -> | ||
R.button { onClick: mkEffFn1 \_ -> setState \s -> { on: not s.on } | ||
, children: [ R.text if on then "On" else "Off" ] | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,27 @@ | ||
module Counter where | ||
|
||
import Prelude | ||
|
||
import Control.Monad.Eff.Uncurried (mkEffFn1) | ||
import React.Basic as R | ||
|
||
-- The props for the component | ||
type ExampleProps = | ||
{ label :: String | ||
} | ||
|
||
-- The internal state of the component | ||
type ExampleState = | ||
{ counter :: Int | ||
} | ||
|
||
-- Create a component by passing a record to the `react` function. | ||
-- The `render` function takes the props and current state, as well as a | ||
-- state update callback, and produces a document. | ||
component :: R.ReactComponent ExampleProps | ||
component = R.react | ||
{ initialState: { counter: 0 } | ||
, receiveProps: \_ _ _ -> pure unit | ||
, render: \{ label } { counter } setState -> | ||
R.button { onClick: mkEffFn1 \_ -> do | ||
setState { counter: counter + 1 } | ||
} | ||
[ R.text (label <> ": " <> show counter) ] | ||
} | ||
module Counter where | ||
|
||
import Prelude | ||
|
||
import Control.Monad.Eff.Uncurried (mkEffFn1) | ||
import React.Basic (ReactComponent, react) | ||
import React.Basic.DOM as R | ||
|
||
-- The props for the component | ||
type ExampleProps = | ||
{ label :: String | ||
} | ||
|
||
-- Create a component by passing a record to the `react` function. | ||
-- The `render` function takes the props and current state, as well as a | ||
-- state update callback, and produces a document. | ||
component :: ReactComponent ExampleProps | ||
component = react | ||
{ displayName: "Counter" | ||
, initialState: { counter: 0 } | ||
, receiveProps: \_ _ _ -> pure unit | ||
, render: \{ label } { counter } setState -> | ||
R.button { onClick: mkEffFn1 \_ -> do | ||
setState \s -> { counter: s.counter + 1 } | ||
, children: [ R.text (label <> ": " <> show counter) ] | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we're using these as record labels, there's no need to escape keywords (at least in recent versions of PureScript).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They become function names though, like
div
. The one that was giving me problems wasdata
. Apparently it's an HTML tag.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't realize
data
was a html tag. None of the others listed inreserved
are html tags are they? @paf31 Wasdata
not causing a problem in the previous version of this script?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assumed I got a newer version of
react-html-attributes
or something. It seemed safer to add everything to the reserved list than have to remember and go back later iftype
ormodule
become elements.