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

Can't use different ReactRender types in render #131

Closed
natefaubion opened this issue Dec 2, 2017 · 1 comment
Closed

Can't use different ReactRender types in render #131

natefaubion opened this issue Dec 2, 2017 · 1 comment

Comments

@natefaubion
Copy link
Contributor

natefaubion commented Dec 2, 2017

The polymorphism over render with ReactRender lets you use different return types, but it's fixed for the class, which means you can't return different types on different ticks of render. I should be able to return a String in one render tick, and a ReactElement in another tick. The correct type I think would be:

{ ... render :: forall r. ReactRender r. ReactThis props state => Eff ... r }

Edit: This is actually wrong, since it means render can't fix the type.
But this higher-ranked type is problematic. I think instead we should just define coercions to ReactElement, since these can actually be used anywhere and not just the root of a render.

fromString :: String -> ReactElement
fromInt :: Int -> ReactElement
fromNumber :: Number -> ReactElement
fromArray :: Array ReactElement -> ReactElement
@natefaubion
Copy link
Contributor Author

I think if we wanted to keep ReactRender, it would be better to actually give it a member, so that it can be overloaded for arbitrary PureScript types.

class ReactRender a where
  toElement :: a -> ReactElement

instance reactRenderString :: ReactRender String where
  toElement = unsafeCoerce :: String -> ReactElement
...

Where the "native" element types are implemented via unsafeCoerce. We should still fix the type of render to return a ReactElement. Users should then opt in with toElement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant