-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Update isReferentiallyTransparentFunctionComponent.js #275
Conversation
If we use the babel plugin to remove |
|
I get your point now. IMO |
@@ -5,7 +5,7 @@ const isReferentiallyTransparentFunctionComponent = Component => Boolean( | |||
!isClassComponent(Component) && | |||
!Component.defaultProps && | |||
!Component.contextTypes && | |||
!Component.propTypes | |||
(!Component.propTypes || process.env.NODE_ENV === 'production') |
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.
Will this line be considered dead code and be eliminated in production?
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.
swapping on process.env.NODE_ENV === 'production' || !Component.propTypes
will avoid getting the propTypes
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.
@istarkov I agree that it would be better. I believe that uglify-js is smart enough to remove those if (!foo.bar || true)
expression but that may not be true with other minifier, they may keep 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.
Yes, I've just tried UglifyJS, both true || foo
and foo || true
work.
I'm wondering about the purpose of `!Component.propTypes`. Using `propTypes` is quite a popular pattern. If it's only here in order to get proper warning in dev mode, that shouldn't prevent us from instantiation less react components. Hopefully, we can use [babel-plugin-transform-react-remove-prop-types](https://github.com/oliviertassinari/babel-plugin-transform-react-remove-prop-types) to increase the number of referentially transparent components
I like this PR 👍 to merge |
@oliviertassinari thanks! |
I agree with @oliviertassinari, the project is moving slowly, that's why we are building "recompact" apart recompose. We will switch to it and use it in production. If the experimentation is a success, we could consider merging the two projects in the future. |
I'm wondering about the purpose of
!Component.propTypes
.Using
propTypes
is quite a popular pattern.If it's only here in order to get proper warning in dev mode, that shouldn't prevent us from
instantiation less react components in production.
Hopefully, we can use babel-plugin-transform-react-remove-prop-types to increase the number of referentially transparent components