-
Notifications
You must be signed in to change notification settings - Fork 46.9k
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
Added new functionality: React.defineComponentMethod #2031
Conversation
…thods with needed policy for all React components.
There are a few technical qualms I have about this. But first, let's decide if we even want something like this. I do wish you would have proposed this somewhere before just doing it. Discussions should be had before making non-trivial architectural changes. @sebmarkbage @jordwalke @petehunt thoughts on this in general? Opening up the doors for anybody to define how any method on a component can behave sounds like a recipe for compatibility disaster. |
Global method overrides creates compatibility issues. We could possibly do this on a component basis, but that defeats the purpose of having mixins do all the boilerplate. I think explicit chaining of super calls would solve this issue with minimal extra boilerplate: #1380 |
Thanks @zpao - I'm absolutely open for discussions. Just didn't know how to start (where to write) and this way is seemed the easiest to start discussion. @zpao, I think you should be agreed that we definitely want something like this and as @sebmarkbage mentioned there is a discussion about this problematique #1380. Thanks sebmarkbage that directed me to this discussion. @sebmarkbage concerns:
In the solution I provided we do not let people override existent methods. But, sure, now I see that there can appear some issues and it may be not the best way to do this.
Yeah, I thought about this, but when you need the same logic for all components it doesn't seem to be DRY if we use mixins. |
Isn't this kind of solved by itself in 0.12? (unless I got it wrong) Then, you'll supply the class and not necessarily have it created by EDIT: Hmm, perhaps I misunderstood the actual request here, but it seems like turning |
@syranide, I don't offer
What I did is let people create extra React component-based methods that will have the same behavior React already provided ( |
@anatolikurtsevich Sorry, I was a bit unclear perhaps, what I meant was that this goes one step in that direction (in my opinion), inheritance is another and there are plenty of other requests for similar features. I don't know how the devs feel, but I feel as if The React mixin-behavior with the magic I'm not necessarily proposing that as the solution (I'm sure there are better ones), but as an example, it uses only traditional patterns to solve the problem and would move the entire responsibility of how to create classes away from React, rather than give React more responsibility. It's now a clear-cut division of responsibility and React no longer forces users into a specific "interpretation of classes". React can certainly still provide helpers. Again, this is up to the devs, but that's how I see it. |
I'll close this out and refer to #1380 which does provide a solution to this problem but we might need a pre-ES6 alternative to do this as well. Let's handle it all in one issue. |
New method React.defineComponentMethod lets us define new methods with a specific policy ("DEFINE_MANY", "DEFINE_MANY_MERGED" and etc.). It provides extra flexibility when you need to have some methods that should collect data and so on.