-
Notifications
You must be signed in to change notification settings - Fork 87
Support 0.14 pure components #34
Conversation
…le functions to include parent in order to extract the identifier from Arrow Function Expressions. Include multiple checks to Arrow Function expressions to modify output of wrapComponent. Update expected test case for pure components.
What kind of strategy do you want to take for |
The default export name should probably be based on filename, the named exports can use their respective names. |
Sounds good, have some initial work for the following cases:
Currently working on default exports for Function Expressions which might require a little more finesse with the Plugin visitors. |
It's not a big deal if we leave out some use cases at the beginning. |
I added you to collaborators so you can continue right on this branch. |
…ementation of React Components as pure Function Declarations and pure Arrow Function Expressions and the implementation details of each. Adds failing case for the Default Export of a Function Expression
Sounds good! Pushed up the changes that I had along with a failing test case for the default export of a function expression. |
What's the module pattern that you wrote down as the edge case? I'm assuming you mean:
Which is similar to the fixtures you have already in
|
…the current visitors added for pure components.
…us changes. This change adds a reset to the foundJSXKey to prevent false positives
By module pattern I mean this way of defining React components: function Something() {
return {
render() { return <div />; }
}
} At least it shouldn't break. |
We also need to make sure we don't wrap class List {
render() {
return <ul>{this.props.items.map(this.renderItem)}</ul>
}
renderItem(item) {
return <ul>{item}</ul>; // using JSX, not called render(), shouldn't be wrapped
}
} |
Oh okay, sounds good. What's the expected result for the module pattern? And for the second example, since React requires that classes extend |
It should be ignored and should not get wrapped (I don't plan to officially support it in transforms, but it shouldn't break either).
I don't want to check the base class because React 0.14 still allows non-Component descendants with a warning. The important part is: false negatives (i.e. not wrapping something) are always better than false positives (wrapping the wrong thing). Are there any false negatives in the current solution? |
What I was trying to say regarding |
That makes total sense! And in regards to any false negatives, I'm going to try and add test cases that it should ignore to make sure. There's nothing I've added to suggest that it will provide false positives, but I definitely need to think more about the different ways people may use JSX in functions that could trigger the current implementation and create a false positive. |
Just a sidenote. If you can figure out a nice way to detect function based React components, that would open way for neater propType definitions. It would be cool to piggyback on Flow annotations without having to use Flow itself. Consider the following: const Viewer = (props: {json: Object, other: Object}) => {
return (
<div>
<div>{'json: ' + JSON.stringify(props.json)}</div>
<div>{'other: ' + JSON.stringify(props.other)}</div>
</div>
);
}; would transform to const Viewer = (props) => {
return (
<div>
<div>{'json: ' + JSON.stringify(props.json)}</div>
<div>{'other: ' + JSON.stringify(props.other)}</div>
</div>
);
};
Viewer.propTypes = {
json: React.PropTypes.object,
other: React.PropTypes.object
}; This would make a fine Babel plugin of its own. Anyway, keep up the good work on the PR. |
@bebraw cool! That sounds really interesting. Could also do something similar with default props if desired. To try to align with the principle of favoring false negatives, I thought that a whitelist style approach might be more suitable. For example, for Arrow Function Expressions we could explicitly state a series of formatters based off of the type of the parent of the node. See: https://gist.github.com/joshblack/8fae4757474422ad632f#file-plugin-js with included actual and expected transforms to complete the POC. This way, we could opt-in to specific transforms that we want to address and reduce the chance of collisions while making it easier to update existing implementations if a case isn't covered. Any thoughts? |
@joshblack Exactly. I have a feeling it would be a nice way to introduce people to a small portion of Flow without forcing them to pick up new tooling. |
How can I help with this issue? I would like to contribute to this but don't know where to start. |
☝️ |
This is on my mind every single day, but I'm busy with other stuff I promised to ship before 0.14 happened. (Namely, Redux Egghead lessons.) |
@gaearon Thanks! If I can help in anyway let me know. Appreciate your hard work on these awesome libraries & tools. |
Asking for ETAs is not really showing appreciation. You can show it better by:
|
@silvenon I would agree with you mostly except for 2. That's just 100% incorrect and I was completely sincere on my offer. I have edited my original message to better reflect what I was trying to ask. Sorry if it came off as |
@joshthecoder what steps have you already taken to help? If you will find predictable easy steps for noob in babel plugins please post'em here, so I won't repeat steps you've taken while figuring out where to start from. |
@Restuta Documentation does seem a bit light at the moment. So far I have just been picking up on it by reading existing plugins such as this one and also have dug around the babel-relay one. |
Moving to #57 since this is out of date. |
Thanks @ericclemmons! |
You might be interested in reduxjs/redux#1455. |
We may still work something out. Not everyone has the option of moving all components & state to a single, re-renderable tree, myself included... :( |
React Hot Loader 3 supports functional components without destroying the state. |
This is initial pass which seems to work together with
react-proxy@react-0.14
with the following limitations:react-transform-catch-errors
because it doesn't know what it's doingWe'll need to address each of those before merging this.