Conditionally use PureComponent instead of Component#1335
Conditionally use PureComponent instead of Component#1335majapw merged 7 commits intoreact-dates:masterfrom
PureComponent instead of Component#1335Conversation
…omponent` instead of `React.Component`
| class CalendarDay extends React.Component { | ||
| const BaseClass = baseClass(); | ||
|
|
||
| class CalendarDay extends BaseClass { |
There was a problem hiding this comment.
this is going to break react linting; we'll need a jsdoc comment to indicate that it extends React.Component
| }; | ||
|
|
||
| class CalendarDay extends React.Component { | ||
| const BaseClass = baseClass(); |
|
|
||
| export const pureComponentAvailable = typeof React.PureComponent !== 'undefined'; | ||
|
|
||
| export default function baseClass(pureComponent = pureComponentAvailable) { |
There was a problem hiding this comment.
why is baseClass a function, but pureComponentAvailable is not?
I'd expect either both to be a function (to support polyfilling of PureComponent, i assume), or neither.
- Both `pureComponentAvailable` and `baseClass` are now functions - Using `extends baseClass()` instead of defining `BaseClass = baseClass()` - Fixing the lint on `DayPickerRangeController` for `pureComponentAvailable` being defined but not used
|
@ljharb what does the jsdoc comment need to be? Your linting system is different than I am used to working with. |
|
(what are you used to working with that’s not eslint?) i believe it’s |
|
@ljharb not in that way. I guess I never knew about being able to do that is a better way of describing it. |
|
@AntiFish03 here's an example: jsx-eslint/eslint-plugin-react#513 (comment) |
|
@AntiFish03 what's the reasoning that the baseClass stuff needs to be in a function, instead of caching it once at module load time? |
|
It doesn't have to be. Just trying to keep it similar to what is used in react-with-styles as was requested. |
…oad, instead of using a function.
|
travis-ci decided to have some timeout issues there for no apparent reason... @ljharb care to restart that and everything should be good to go |
|
After a few discussions, i wonder if it'd be worth it to try something like this? /** @extends React.Component */
class Foo extends React.PureComponent || React.Component {
[React.PureComponent || 'shouldComponentUpdate'](nextProps, nextState) {
return shallowCompare(this, nextProps, nextState);
}
}Otherwise, your change LGTM. |
|
@ljharb, Change made as requested anything else? |
ljharb
left a comment
There was a problem hiding this comment.
With appropriate documentation - including telling people that they can overwrite build/utils/baseClass.js with module.exports = React.PureComponent if they know they're using a newer React - this LGTM.
|
@ljharb, Readme updated. |
majapw
left a comment
There was a problem hiding this comment.
This looks great! Thank you so much for making this change.
| @@ -1,4 +1,9 @@ | |||
| import React from 'react'; | |||
| if (process.env.NODE_ENV !== 'production') { | |||
| const {whyDidYouUpdate} = require('why-did-you-update'); | |||
There was a problem hiding this comment.
nit: spaces around the whyDidYouUpdate
const { whyDidYouUpdate } = require('why-did-you-update');
| import shallowCompare from 'react-addons-shallow-compare'; | ||
|
|
||
| class BaseClass extends (React.PureComponent || React.Component) { | ||
| [React.PureComponent || 'shouldComponentUpdate'](nextProps, nextState) { |
There was a problem hiding this comment.
I'm not sure I fully understand what this will do in the case that React.PureComponent is defined
There was a problem hiding this comment.
oh right, this should be React.PureComponent && - so that it's undefined in that case, instead of the method name
There was a problem hiding this comment.
shouldn't it actually be !React.PureComponent && so that it injects the shouldComponentUpdate when PureComponent isn't available.
There was a problem hiding this comment.
aha, yes, that's better. coding is hard.
majapw
left a comment
There was a problem hiding this comment.
Gonna put an X on this temporarily so that || doesn't accidentally get merged in
|
So fun fact, I believe that this breaks react-dates in IE10. sigh It seems to be related to how this is transformed by babel (current working theory is something about the double-extends). |
…Upgrade"" This reverts commit 50c382f.
|
@majapw all of a sudden I am getting Is this something you are seeing also? |
|
@AntiFish03 locally or in storybook? on the latest version? |
|
@majapw, Locally from master. |
…eComponent-Upgrade""
Working to resolve #1297. Conditionally using
React.PureComponentinstead ofReact.Component