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

error when pattern matching on props #104

Closed
coot opened this issue Jul 14, 2017 · 2 comments
Closed

error when pattern matching on props #104

coot opened this issue Jul 14, 2017 · 2 comments

Comments

@coot
Copy link

coot commented Jul 14, 2017

Consider a react class:

data Message
  = Hello
  | Bye

instance showMessage :: Show Message where
  show Hello = "Hello :)"
  show Bye = "Bye!"

cls :: ReactClass Message
cls = createClass (spec unit renderFn)
  where
    renderFn this = do
      msg <- getProps this
      pure $ div' [ text (show msg) ]

When rendering it PureScript will fail to pattern match on Hello and Bye and will error.

index.js:34228 Uncaught Error: Failed pattern match at Main line 24, column 1 - line 24, column 37: Object

screenshot from 2017-07-14 19-14-32

@coot
Copy link
Author

coot commented Sep 23, 2017

There are two possible workarounds for this:

  • ask the user to wrap the type inside a record.
  • we do that for him for props the same way it is done for state already

I prefer the second choice as it will support all the language features out of the box, but this adds some runtime overhead (creating the wrapper objects & gc them after they become unreferenced).

@ethul
Copy link
Contributor

ethul commented Mar 4, 2018

As of #129, props are now records. I believe the above should not longer be an issue.

@ethul ethul closed this as completed Mar 4, 2018
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

2 participants