Skip to content
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

Minor cleanup work #555

Merged
merged 6 commits into from
Feb 6, 2018
Merged

Minor cleanup work #555

merged 6 commits into from
Feb 6, 2018

Conversation

DavidJFelix
Copy link
Contributor

I got a bit sidetracked with refactoring apollo-link. I was having a hard time groking 1000 line stateful components so I started doing some cleanup work wherever I saw low hanging fruit.

I'm working my way into the editor codebase a bit to make it a bit easier to swap out the fetcher.

Here are the granular commits that I have working so far.

key={operation.name ? operation.name.value : '*'}
className={operation === highlight ? 'selected' : ''}
// tslint:disable-next-line
onMouseOver={() => onMouseOver(operation)}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using React.SFC sounds very interesting!
What I'm a little bit concerned about, however, is the use of arrow functions, which is an antipattern for normal components, as the function reference of the arrow function changes on each rerender, so do the props for the element. What do you think about that?

Copy link
Contributor Author

@DavidJFelix DavidJFelix Feb 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was actually blocked by tslint for this very reason and wasn't sure what it was talking about. I think this particular instance is fine because a majority of the props which could initiate a rerender (in these two specific cases) are the ones that create the functions, which is why I added the tslint disable. I also learned my disable on tslint from another edited file which does the same thing for a simple lambda.

Long term my intention is to do another pass on these components and create a higher order component which passes a function directly into the SFC and only updates that specific function when components involved in it change. I was looking at recompose for this, but I'm open to suggestions.

For the short term, I'm not terribly concerned about the performance impact.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thanks for giving your perspective on that one.
All other refactorings in this PR make a lot of sense to me, as they're simplifying a lot, but for this component, I don't see clear benefits for moving to this solution.

I'd rather stay with the normal component, which by the way could also be a pure react component.
We have severe performance problems in the Playground (which I'm looking into right now) - we have to be really mindful of changes like these.

So my suggestion: Putting the arrow functions back to instance methods and turning the component into a React.PureComponent

key={operation.name ? operation.name.value : '*'}
className={operation === highlight ? 'selected' : ''}
// tslint:disable-next-line
onMouseOver={() => onMouseOver(operation)}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thanks for giving your perspective on that one.
All other refactorings in this PR make a lot of sense to me, as they're simplifying a lot, but for this component, I don't see clear benefits for moving to this solution.

I'd rather stay with the normal component, which by the way could also be a pure react component.
We have severe performance problems in the Playground (which I'm looking into right now) - we have to be really mindful of changes like these.

So my suggestion: Putting the arrow functions back to instance methods and turning the component into a React.PureComponent

@DavidJFelix
Copy link
Contributor Author

@timsuchanek implemented changes.

@DavidJFelix
Copy link
Contributor Author

give me a sec. i'm rebasing

@DavidJFelix
Copy link
Contributor Author

All cleaned rebased and should have the changes we discussed.

@timsuchanek timsuchanek merged commit 32c873a into graphql:master Feb 6, 2018
@timsuchanek
Copy link
Member

Thanks for the work @DavidJFelix !

@DavidJFelix
Copy link
Contributor Author

No problem. Thanks for the collab. You'll probably see some more cleanup from me in the near future.

cgxxv pushed a commit to cgxxv/graphql-playground that referenced this pull request Mar 25, 2022
* chore: remove empty file

* chore: Convert ExecuteButtonOperation to a SFC

- Stateless functional component

* chore: make cleanup toggle and spinner

* chore: make results more functional

* chore: move execute button operation from SFC to purecomponent

per discussion in graphql#555

* chore: remove pre-return commands from render in editor

- Trying to move towards stateless, so I'm removing the pre-return
render code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants