Skip to content
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

React 16 #109

Merged
merged 8 commits into from
Nov 2, 2017
Merged

React 16 #109

merged 8 commits into from
Nov 2, 2017

Conversation

coot
Copy link

@coot coot commented Aug 5, 2017

This solves #102. It may suffer from #105 if one is using props polymorphically, as in:

cls :: forall r. ReactRender r => ReactClass { r :: r }
cls = createClassStateless \{ r } -> r

it would be nice to have a warning in this case, but I think that's impossible. It would need to be shown only if one is passing cls to createElement directly but not if one is specialising the class. So it's ok to use the following goodCls:

goodCls :: ReactClass { r :: ReactElement }
goodCls = cls

but this leads to #105:

    -- somewhere in a render function
    render _  = pure $ createElement (cls :: ReactClass { r :: Array ReactElement }) { r: [] } []

@coot
Copy link
Author

coot commented Aug 5, 2017

@paf31 Thermite is using a monoid structure on Spec that's based on array of react elements, something similar will be possible on the level of ReactClass-es. You can have a monoid which allows multiplication between ReactElement's or Array ReactElement by creating an Array whenever it's needed. That would make larger Thermite UI's more performant.

@paulyoung
Copy link
Contributor

Are there any plans to merge this now that React 16 has been released?

@coot
Copy link
Author

coot commented Sep 27, 2017

I would like to review this (against the release notes) before it's merged.

@coot
Copy link
Author

coot commented Sep 30, 2017

Here are all the types that react supports:

  • ReactElement
  • String
  • Number
  • null
  • Boolean
  • portals - they need to be added to purescript-react-dom

Should we support null (and Boolean)?

I actually would prefer to not use a type class but a variant. This way one can render a list which consists of the various types, and avoids #105.

@coot
Copy link
Author

coot commented Sep 30, 2017

Using a sum type will add a runtime overhead, since one will need to traverse an array and coerce its elements, so that's probably not the best approach. So at the end I think the class based approach is better.

Also add `React.DOM.int` and `React.DOM.number` functions.
@ethul
Copy link
Contributor

ethul commented Sep 30, 2017

I like the class-based approach. However, I would also be open to an implementation using a sum too.

On a side note, what does everything think about adding a class for createElement? I was thinking this might be a nice way to handle stateless classes instead of createClassStateless. For example, something like:

class ReactCreateElement a
instance reactClassReactCreateElement :: ReactCreateElement (ReactClass props)
instance reactStatelessReactCreateElement :: ReactCreateElement (props -> ReactElement)

createElement :: forall props. ReactCreateElement class => class -> props -> Array ReactElement -> ReactElement

@ethul ethul mentioned this pull request Oct 4, 2017
-- | where
-- | hellowWorldCls props = ...
-- | ```
-- | Then the `displayName` will be set up to `HellowWorldCls`
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue #118 @ethul this might be a bit surprising but it's best of what we can get.

@ethul
Copy link
Contributor

ethul commented Oct 11, 2017

Thanks for making these updates!

I think this is great to have the displayName set via the name of the function. However, I am wondering if we need to run it through the capitalize function. Would it be clear to the developer to simply just use the f.name as-is?

Also, on a side note, is the wW in hellowWorldCls intentional?

@coot
Copy link
Author

coot commented Oct 12, 2017

It's just a convention in react ecosystem. Foreexample enzyme will look only for capitalised components.

The wW is just a typo.

@ethul
Copy link
Contributor

ethul commented Oct 12, 2017

Gotcha. Thanks for the info

@uzantnomo
Copy link

@coot it isn't merely a convention, lowercase and capitalized components are treated differently in JSX.

Changing displayName of a component might be confusing, and perhaps should be avoided, if it doesn't break any tools.

@coot
Copy link
Author

coot commented Oct 12, 2017

That's a good point.

@coot
Copy link
Author

coot commented Oct 18, 2017

@ethul what about merging this PR?

@ethul
Copy link
Contributor

ethul commented Oct 18, 2017

Thanks for the ping. I would like to take a bit more time to review all of these changes and dig into the display name further. I should be able to go through this over the next few days. Sorry for the delay!

@ethul
Copy link
Contributor

ethul commented Nov 2, 2017

@ethul ethul merged commit dbbf740 into purescript-contrib:master Nov 2, 2017
@ethul ethul mentioned this pull request Nov 2, 2017
@coot coot deleted the react-16 branch November 2, 2017 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants