Skip to content

Change query to queries #72

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

Merged
merged 1 commit into from
Aug 27, 2018

Conversation

gribnoysup
Copy link
Contributor

A possible solution for #69

As described in this issue:

  • query prop is removed
  • queries prop is added
  • queries prop values are media queries (and not the prop itself)
  • render and children props are both functions and render prop is an alias for children (they behave the same way)

I changed tests for browser environment and also added new tests for the server environment.

Copy link
Member

@mjackson mjackson left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! The changes look great, for the most part. I've made a few comments about things I'd like to address before merging.

ReactDOMServer.renderToStaticMarkup(
<Media queries={queries}>
{matches => {
expect(matches).toMatchObject(expected)
Copy link
Member

Choose a reason for hiding this comment

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

Let's make the assertion on the markup instead of in the render prop and change the assertion to be something like "it renders all queries".

ReactDOMServer.renderToStaticMarkup(
<Media queries={queries} defaultMatches={defaultMatches}>
{matches => {
expect(matches).toMatchObject(defaultMatches)
Copy link
Member

Choose a reason for hiding this comment

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

Same as above.

ReactDOM.render(
<Media queries={queries}>
{matches => {
expect(matches).toMatchObject(expected)
Copy link
Member

Choose a reason for hiding this comment

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

Let's test the output of render instead of the arguments to the render prop, just so we have complete coverage, and change the description to be something like "it renders its children function" or similar.

it('should call children with expected values', () => {
ReactDOM.render(
<Media queries={queries} render={matches => {
expect(matches).toMatchObject(expected)
Copy link
Member

Choose a reason for hiding this comment

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

Same as above.

ReactDOM.render(
<Media queries={queries}>
{matches => {
expect(matches).toMatchObject(expected)
Copy link
Member

Choose a reason for hiding this comment

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

Same as above.

it('should call children with expected values', () => {
ReactDOM.render(
<Media queries={queries} render={matches => {
expect(matches).toMatchObject(expected)
Copy link
Member

Choose a reason for hiding this comment

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

Same as above.

ReactDOM.render(
<Media queries={queries}>
{matches => {
expect(matches).toMatchObject(expected)
Copy link
Member

Choose a reason for hiding this comment

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

Same as above.

it('should call children with expected values', () => {
ReactDOM.render(
<Media queries={queries} render={matches => {
expect(matches).toMatchObject(expected)
Copy link
Member

Choose a reason for hiding this comment

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

Same as above.

modules/Media.js Outdated
}

render() {
const { children, render } = this.props
const { matches } = this.state

return (
Copy link
Member

Choose a reason for hiding this comment

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

Let's make changes to the rendering logic in a separate PR, please. As written, this change eliminates support for non-function children.

Copy link
Contributor Author

@gribnoysup gribnoysup Oct 23, 2017

Choose a reason for hiding this comment

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

Sure! I think I just didn't understand correctly what you meant in the issue comment :)

@gribnoysup
Copy link
Contributor Author

gribnoysup commented Oct 24, 2017

Hi @mjackson

I updated the PR, but there are some alterations to the render logic, because beforematches was just a flag, and now it is an object with multiple flags.

I tried to recreate the behavior of the render method as close as possible to the one, that is in the master branch:

  • render prop not called at all when there are no matches with the queries (same as before)
    • render now have matches as a first argument (new)
  • children component is not rendered at all if there are no matches (same as before)
    • we provide matches as a prop only if the child is a composite component (new behavior)
  • children function always called with matches as a first argument (same as before)

The tests are also updated

@gribnoysup
Copy link
Contributor Author

Resolved merge conflicts and prettified everything

@flushentitypacket
Copy link

@gribnoysup Was this closed intentionally?

@edorivai
Copy link
Collaborator

@gribnoysup I feel like this was closed accidentally, feel free to close again if it was really closed on purpose. @mjackson do you still feel like releasing this as v2? Looking at #69 there's quite some interest in the feature!

@edorivai edorivai reopened this Aug 26, 2018
@gribnoysup
Copy link
Contributor Author

gribnoysup commented Aug 26, 2018

Hi @edorivai! I didn't see any updates for the PR after I made all the changes so I assumed that it is not needed anymore. TBH resolving conflicts with prettier changes in master was hard enough the first time, so if this PR is needed I would rather just do it from scratch

@gribnoysup gribnoysup force-pushed the feature/media-queries branch from 5062135 to 634c61f Compare August 26, 2018 11:15
@gribnoysup
Copy link
Contributor Author

gribnoysup commented Aug 26, 2018

Done, the branch is updated. Hope it wouldn't go stale again 😅

@edorivai edorivai changed the base branch from master to next August 27, 2018 09:14
@edorivai edorivai merged commit 1fb713b into ReactTraining:next Aug 27, 2018
@edorivai
Copy link
Collaborator

@gribnoysup thanks a lot! I decided to merge into the next branch for now, as these changes are breaking and we'll probably want to release it as a major version bump.

@mjackson How would you want to move forward from here? Perhaps cut a v2 alpha release?

@gribnoysup gribnoysup deleted the feature/media-queries branch August 27, 2018 10:16
@Newnab
Copy link

Newnab commented Nov 29, 2018

What's the current status of this? Is it still in the works?

I have a use case where lots of props on a component (in my case, a datepicker) are changed depending on which media queries match, and it would be preferable to me to have a way to have multiple queries in one rather than declaring the component multiple times inside separate components, if possible!

@edorivai
Copy link
Collaborator

Hey @Newnab 👋

The status is that we're waiting for @mjackson to jump in and publish the changes to npm. It seems that Michael is a bit busy lately, so I'm not sure when he'll take a look here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants