You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, DOM elements accept an array of Props. An alternative to this could be to define a row representing the known attributes one may pass as props to a DOM element. Using a row was briefly mentioned in #113 (comment).
For instance, we could define two rows: one for HTML attributes and one for SVG attributes. Going this route, we would need a way to handle passing event handler callbacks. Also, if we wanted an attribute to have a type other than a primitive one or one known to React, then we would need a way to map the attribute's value to something React can use.
I think using rows could prove to be nicer in terms of syntax and perhaps a bit more convenient. I wanted to bring up this idea to see if there is interest in going this route. I'd be happy to discuss other ideas or dig in deeper with rows if there is interest. Any comments, questions, or suggestions are most welcome.
Also, below are some options for what this could look like. Option 1 presents passing a record where the row must be a subrow of all HTML attributes. Option 2 is similar, but passes a Data.Record.Builder. Using a builder we have the opportunity to pass data types other than primitive ones; e.g., instead of the target function accepting a String, we could make a Target data type and map it to a String in the function. Just a couple of ideas, others are most welcome.
Option 1 - Records
typeHTMLAttributesr= ( href :: String
, target :: String
| r
)
a
::forallrst
. Unionrt (HTMLAttributess)
=>Recordr->ArrayReact.ReactElement->React.ReactElement
a props children = React.createElementTagName "a" props children
foo::React.ReactElement
foo =
a
{ href: "https://github.com/purescript-contrib/purescript-react"
, target: "_blank"
} [ ... ]
Option 2 - Builder
typeHTMLAttributesr= ( href :: String
, target :: String
| r
)
href
::forallr
. RowLacks "href" r=>String->Builder { | r } { href :: Int | r }
href = Builder.insert (SProxy::SProxy "href")
target
::forallr
. RowLacks "target" r=>String->Builder { | r } { target :: String | r }
target = Builder.insert (SProxy::SProxy "target")
a
::forallrst
. Unionrt (HTMLAttributess)
=>Builder { } (Recordr)
->ArrayReact.ReactElement->React.ReactElement
a builder children = React.createElementTagName "a" (Builder.build builder {}) children
foo::React.ReactElement
foo =
a
( href "https://github.com/purescript-contrib/purescript-react"
>>> target "_blank"
) []
react-basic uses records and Union through FFI coercions on the DOM builders. I think the builder approach is an interesting alternative, but I think it could probably be built on top of what we have, right? Maybe we could try that first. I think that the dictionary overhead will be significant right now. In 0.12 we'll get compiler-solved Nub and Lacks which means lighter-weight, and correct record merges, so we may be able to use records directly. When you use rows though you always have to be careful about how constraints are propagated since it can destroy the referential identity of react classes.
Currently, DOM elements accept an array of
Props
. An alternative to this could be to define a row representing the known attributes one may pass as props to a DOM element. Using a row was briefly mentioned in #113 (comment).For instance, we could define two rows: one for HTML attributes and one for SVG attributes. Going this route, we would need a way to handle passing event handler callbacks. Also, if we wanted an attribute to have a type other than a primitive one or one known to React, then we would need a way to map the attribute's value to something React can use.
I think using rows could prove to be nicer in terms of syntax and perhaps a bit more convenient. I wanted to bring up this idea to see if there is interest in going this route. I'd be happy to discuss other ideas or dig in deeper with rows if there is interest. Any comments, questions, or suggestions are most welcome.
Also, below are some options for what this could look like. Option 1 presents passing a record where the row must be a subrow of all HTML attributes. Option 2 is similar, but passes a
Data.Record.Builder
. Using a builder we have the opportunity to pass data types other than primitive ones; e.g., instead of thetarget
function accepting aString
, we could make aTarget
data type and map it to aString
in the function. Just a couple of ideas, others are most welcome.Option 1 - Records
Option 2 - Builder
// @natefaubion
The text was updated successfully, but these errors were encountered: