-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Components: Turn a few into Component classes #19102
Conversation
// initialState is also used to reset state when a the taxonomy prop changes | ||
static initialState = { | ||
searchTerm: '', | ||
requestedPages: [ 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.
The operations on this.state.requestedPages
seem to be safe, but with this change I'd advocate using Object.freeze
on any array/object in Component.defaultProps
or Component.initialState
.
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.
analyticsPrefix: 'Category Selector', | ||
searchThreshold: 8, | ||
loading: true, | ||
terms: [], |
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.
Want to Object.freeze
this too?
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.
Oops, oversight of mine. ccd4ee7
Discovered something pre-existing that didn't seem right: 2811098 |
@@ -3,10 +3,8 @@ | |||
* | |||
* @format |
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.
Want to pull @format
out of external deps?
I've looked over this file and smoke tested via the post editor. Looks good 👍
(a review in parts)
@@ -3,9 +3,8 @@ | |||
* |
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.
I smoke tested followers-data
and email-followers-data
and there seem to be no regressions 👍
Interesting, first time I've seen the DataComponent
wrapper in Calypso 🤔
@@ -3,9 +3,8 @@ | |||
* |
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.
I smoke tested followers-data
and email-followers-data
and there seem to be no regressions 👍
Interesting, first time I've seen the DataComponent
wrapper in Calypso 🤔
Also fixes an incorrect component name in README
@@ -3,9 +3,8 @@ | |||
* |
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.
👍 Smoke tested and learned about viewers (only available on private, non-Jetpack sites).
I pushed a commit which names exported default classes. The names were lost since |
highlightedIndex: -1, | ||
showSearch: false, | ||
isKeyboardEngaged: false, | ||
}; | ||
|
||
state = this.constructor.initialState; | ||
|
||
reset() { |
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.
I was trying to trigger this to confirm correct behavior, but it appears to be unused. Can you find whether this method is referenced anywhere? We might be able to simplify this further and not need to make the initialState
changes.
Looks like this was introduced in #5808 by @marekhrabe (8b08a8f).
Can you say whether it's safe to remove this method which doesn't appear to be called?
👍 I'd like to rip it out if possible, but this file looks good either way.
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.
Reset is not in use right now. It was part of work for #8739 that wasn't implemented. I think it's safe to remove now and simplify the initialState declaration. It can be easily reintroduced once we are sure we need it.
@@ -9,10 +9,10 @@ A component that fetches a private wpcom site's viewers and passes them to its c | |||
|
|||
## Usage | |||
|
|||
A component wrapped with `<FollowersData />` will receive the following props: |
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.
Just fixing wrong component reference.
@@ -3,15 +3,12 @@ | |||
* |
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.
Smoke tested, works well 👍
@@ -3,10 +3,8 @@ | |||
* |
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.
👍 smoke tested
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.
💪 Everything seems to work well, nicely done!
It would be nice to completely remove the reset
and the initialState
it requires if we can determine that's safe.
Great work on this PR! 💖 |
Thanks a lot for reviewing @sirreal and for chiming in @marekhrabe!
|
Most of these weren't migrated by the `create-class` codemod before because they contained a reference to `this.getInitialState()` in some method (to reset the component to its initial state after some user interaction). This can be resolved by defining `static initialState = {...}; state = this.constructor.initialState;`, and replacing the reference to `this.getInitialState()` by `this.constructor.initialState`. Since `SiteSelector` wasn't actually using the `reset()` method which referenced `this.getInitialState()`, that method was removed altogether (props @sirreal!). Finally, this PR fixes an incorrect component name in `<ViewersData />`'s README, as well as the affected components' `@format` comment headers.
Modeled after #19085. I grepped for
this.getInitialState()
and did the following (same as #19085 (comment)):this.getInitialState()
call with a dummy (I used a string,'intialState'
😄 )createReactClass
withReact.createClass
so the codemod would pick it upintialState
static, use it to initstate
, and replace the dummy'initialState'
string with it.To test: Verify that the affected components still work as before.