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

Remove findDomNode from withHoverAreas by making a render prop component #11407

Merged
merged 2 commits into from
Nov 6, 2018

Conversation

youknowriad
Copy link
Contributor

Related #11360

This PR removes findDOMNode from the withHoverAreas Higher Order Component by making it a component with a render prop. (This would be the perfect use-case for a React hook :) )

Make sure to view the diff without "whitespace" diff

@youknowriad youknowriad added the [Type] Code Quality Issues or PRs that relate to code quality label Nov 2, 2018
@youknowriad youknowriad self-assigned this Nov 2, 2018
@youknowriad youknowriad requested a review from a team November 2, 2018 13:11
@youknowriad youknowriad added this to the 4.3 milestone Nov 2, 2018
@youknowriad youknowriad mentioned this pull request Nov 2, 2018
12 tasks
@gziolo gziolo self-requested a review November 5, 2018 08:26
Copy link
Member

@noisysocks noisysocks left a comment

Choose a reason for hiding this comment

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

Nice!

I tested this by hovering my mouse over different blocks in the demo post and nothing seems to have regressed.

Left some minor suggestions on how to improve the comprehensibility of WithHoverAreas.

Some unit tests for WithHoverAreas would be ace, but since they're missing in master that's not a blocker.

{ shouldShowMobileToolbar && (
<BlockMobileToolbar
<WithHoverAreas>
{ ( { bindContainer, hoverArea } ) => {
Copy link
Member

Choose a reason for hiding this comment

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

Did you consider changing BlockListBlock to use createRef() and then having it share this ref with <WithHoverArea>?

<WithHoverAreas containerRef={ this.blockListRef }>
	{ ( hoverArea ) => {
		...
	} }
</WithHoverAreas>

I think this makes it a little clearer that the "container" is something that's passed in to WithHoverAreas.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good ideal, I'll try it.

if ( this.state.hoverArea ) {
this.setState( { hoverArea: null } );
}
toggleListeners( shouldRemoveEvents ) {
Copy link
Member

Choose a reason for hiding this comment

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

I would expect the sole boolean argument of toggleListeners to work the opposite way.

this.toggleListeners( true ); // Adds the listeners
this.toggleListeners( false ); // Removes the listeners

this.onMouseLeave = this.onMouseLeave.bind( this );
this.onMouseMove = this.onMouseMove.bind( this );
}
class WithHoverAreas extends Component {
Copy link
Member

Choose a reason for hiding this comment

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

The convention we seem to follow is that components beginning with with are HOCs. In other places that we've used components with render props, we've named it something more conventional, e.g. PostTaxonomies.

(HoverArea would be my suggestion here.)

@youknowriad youknowriad force-pushed the remove/find-dom-node-with-hover-areas branch from 3caeb8c to 3f15f77 Compare November 6, 2018 10:01
@youknowriad youknowriad merged commit 08e3154 into master Nov 6, 2018
@youknowriad youknowriad deleted the remove/find-dom-node-with-hover-areas branch November 6, 2018 10:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Code Quality Issues or PRs that relate to code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants