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

Editor: Add ifPostTypeSupports higher-order component (try conditional render HoC pattern) #4815

Closed
wants to merge 2 commits into from

Conversation

aduth
Copy link
Member

@aduth aduth commented Feb 1, 2018

This pull request seeks to implement a new ifPostTypeSupports higher-order component which serves in place of the existing PostTypeSupportCheck and attempts to explore a new generalized pattern for conditional component rendering.

Example Before:

function MyFeaturedImage() {
	return (
		<PostTypeSupportCheck supportKeys="thumbnail">
			<img />
		</PostTypeSupportCheck>
	);
}

export default connect( /* ... */ )( MyFeaturedImage );

Example After:

function MyFeaturedImage() {
	return <img />;
}

export default compose( [
	ifPostTypeSupports( 'thumbnail' ),
	connect( /* ... */ ),
] )( MyFeaturedImage );

Implementation notes:

The thinking behind the naming convention is that we could create higher-order component-libraries with the following expectations:

Name Behavior
ifSomeCondition Renders component only if condition applies
withSomeProps Renders component with additional props

Testing instructions:

Verify that there are no regressions in the behavior of post-type-conditional elements:

  • Discussion (comments or trackbacks supports)
  • Featured image (thumbnail support)
  • Excerpt (excerpt support)
  • Post format (post-formats support)
  • Author (author support)
  • Order (page-attributes support)
  • Last Revision (revisions support)

@aduth aduth added the [Type] Question Questions about the design or development of the editor. label Feb 1, 2018
@gziolo
Copy link
Member

gziolo commented Feb 1, 2018

@jorgefilipecosta opened a similar PR. See #4812. In general both implementation are similar 😃

@aduth
Copy link
Member Author

aduth commented Feb 1, 2018

Well then... 😅

I think we could probably combine the two branches:

  • Take README.md and completed replacement of PostTypeSupportsCheck from mine...
  • ...and withConditionalRender (good idea!) and tests from @jorgefilipecosta 's

Can take a look tomorrow, or if @jorgefilipecosta wants to go ahead, by all means.

@jorgefilipecosta
Copy link
Member

Thank you @aduth, I will merge both PR's 👍

@gziolo
Copy link
Member

gziolo commented Feb 2, 2018

Thank you @aduth, I will merge both PR's

Yes, that would be nice. This one answers also some questions I had in the other PR :)

@aduth
Copy link
Member Author

aduth commented Feb 7, 2018

Closing in favor of #4812.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Question Questions about the design or development of the editor.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants