-
Notifications
You must be signed in to change notification settings - Fork 65
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
Consider alternative ReactClass API #124
Comments
An example of how it fixes ref issues. Note this just uses myClass = component "MyClass" \this -> do
el <- newRef null
let
render = pure $
D.div
[ P.withRef (writeRef el) ]
[]
pure { state: unit, render } |
It should also be possible to recover some form a typeclass abstraction by monomorphizing ReactClasses within the constructor. It's a bit awkward, but possible. |
Sorry, what is the "module pattern"? I'm all for discussing improvements to the API, but maybe we can break this down into some smaller individual changes? Another thing I've been thinking is that there might be different sets of React bindings. The goal here was to have something low-level and minimal, although it's probably diverged a bit from that now. But there's no reason this couldn't be implemented as a separate library. |
The "module pattern" is just JS terminology for using a closure for private instance state and returning a record as the object's interface, rather than using It's possible that this could be a different library, and we may do that, but I'd like to see if that's necessary. The core bindings here were written when |
I played with the Nate’s gist today and I really liked it. It allows for a much more idiomatic way of writing react components and is in better harmony with the way react is designed to be used. I feel like it’s a big step in the right direction. If we nix the effect types in 0.12, this will be a sweet react library. To me, the effects really get in the way. I’d rather spend the time actually fixing the bug they could have prevented then spend the time fixing the compiler errors. Especially when passing callbacks and wrapping components and all the things you want to do in react. |
FWIW I use |
EventHandler and not EventHandlerContext? Could you show me how that works? |
@born2defy https://github.com/purescript-contrib/purescript-react/blob/master/src/React.purs#L439. |
I assume the idea would be to replace the spec type with the code you have there. Could you please make a PR so that we can see what it would look like? |
I've opened a PR here: #129 |
Closed by #129 |
We are using an alternative ReactClass API internally, and I think it should be considered for upstream.
https://gist.github.com/natefaubion/c639440f2fafd079c5d4eb36012d8e0e
It's basically the module pattern, but has several notable improvements:
create-react-class
which is unsupported and has lots of unnecessary machineryUnion
for calculating the available lifecycle fields, so there's no need for special-casingcomponentDidCatch
(only provide the ones you need).PureComponent
, and disallowsshouldComponentUpdate
in that case.ReactThis
reference up front in the constructor, and you don't need to pass it around everywhere.The text was updated successfully, but these errors were encountered: