-
Notifications
You must be signed in to change notification settings - Fork 49
Support Class Functions as React Props #221
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
base: main
Are you sure you want to change the base?
Conversation
Thanks for your contribution, @omrimn . There are a few things that will need to be addressed before this feature can be added to the r2wc mainline.
|
I thought of another thing: Your transformer isn't defining a property for the prop value on the element, which may cause some surprise if a user changes the method and the React component doesn't update. Let me try to explain this better:
Now what you're proposing here is a second property on the element, pointed to by the value of the first, that's going to hold a function. But what if that second property's value changes? Should a user expect that to cause a React root update and trigger effects/memos/etc. that depend on that function? I'd say probably! We didn't do this on the global for the |
…d support updates to the class function to rerender the React component with the new method assigned
@bmomberger-bitovi Thanks a lot for the detailed replay and your thought.
|
Thanks for the updates. I'm on vacation for the next week but I'll re-review your PR when I return. |
@bmomberger-bitovi could you please re-review the changes? 🙏🏻 Thanks ! |
Overview
This PR enhances the function transform logic to support resolving functions defined as class methods on the custom element's container. Previously, only global or window-scoped functions could be referenced by name.
Now, if a function prop is passed as an attribute and matches a method on the element's container (using camelCase conversion), it will be correctly resolved and bound to the element.