-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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
[ReactNative] Export EdgeInsetsPropType and PointPropType #262
Conversation
// | ||
var ReactNative = Object.assign(Object.create(require('React')), { | ||
var ReactNative = Object.assign(Object.create(React), { | ||
React, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @vjeux - any reason not to do this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a thread on react about this. The main counter argument is that it introduces a cyclic dependency so it's a nightmare to console.log. But, this would make the require boilerplate shorter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
console.log should handle cycles anyway so you can debug cyclic objects. That said I think there isn't a cycle for ReactNative since the Object.create(React) is not the React object, so assigning React to the clone doesn't introduce a cycle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally this strikes me as a little weird and I don't want it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this instance there's no cycle since react-native is exporting React along with some other native extensions. Another option is remove the Object.assign bit and just have:
// react-native.js
module.exports = {
React: require('React'),
// react native components
};
and then have the pattern for using it be var {React, View} = require('react-native')
or alternatively
var ReactNative = require('react-native');
var {React, View} = ReactNative;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we were going this way, we should probably not extend from React.
var {React, View} = require('react-native'); // good
var React = require('react-native');
React.createClass // bad, only in React.React
var ReactNative = require('react-native');
ReactNative.React.createClass // good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vjeux I think so too. Perhaps the question we should answer is whether destructuring assignment is the right pattern for the react-native module.
In web React's case, we usually write var React = require('react')
and JSX handles the basic DOM components, so we don't write var {div, span} = require('react');
.
With React Native, does it make more sense to lowercase the basic components like View, Text, Image, and maybe Touchable* and let JSX handle them? Other components and libraries like Navigator and Vibration would be published as separate packages, which helps reduce the size of the JS bundle as well. The code would look like:
var React = require('react-native');
var Navigator = require('react-native-navigator');
var Vibration = require('react-native-vibration');
...
render() {
return <view style={styles.container}><text>hi</text></view>;
}
...
var styles = React.createStyleSheet({
container: {flex: 1}
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are many issues with
var React = require('react-native');
var Navigator = require('react-native-navigator');
var Vibration = require('react-native-vibration');
The first one is that we're going to run into naming conflicts with npm. Someone else will steal a name that we want and we're going to either reach out and negotiate or use a less ideal one.
Then, you're running into crazy dependency issues where you have different versions of all of those plugins and conflicts. We really want to ship one bundle where everything is in sync for the core components.
One idea I had is:
var React = require('react-native/react');
var Navigator = require('react-native/navigator');
var Vibration = require('react-native/vibration');
Everything is bundled together, no namespace clash and we don't bundle things that we don't use
89e62f2
to
c7d9d3b
Compare
213cb43
to
8de56cc
Compare
I removed the React self-export so now this is just the struct prop types and the static renderers. |
c3a8f7a
to
2f7da3b
Compare
55c9ee9
to
5fc2943
Compare
A more modern approach will do rendering early, and store the descriptor (the result of the render) in the component state, and get inlined in the render function. |
Removed Static helpers, it's now just prop types for EdgeInsets and Point. |
Added the EdgeInsets and Point PropTypes.
LGTM - @ericvicenti: can you import and land? |
Actually I'll just take it. |
@facebook-github-bot import |
Thanks for importing. If you are an FB employee go to https://our.intern.facebook.com/intern/opensource/github/pull_request/1057649787583002/int_phab to review. |
Summary: Added some more exports to React that are either necessary or often useful for component authors. Closes facebook#262 Github Author: James Ide <ide@jameside.com> Test Plan: Imported from GitHub, without a `Test Plan:` line.
* Add support for macOS legacy scroller system setting. * Add missing comment. Whitespace cleanup * Add locals * Fixed ] in comment
Added some more exports to React that are either necessary or often useful for component authors.