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

[feature]: Adding a window size hook #1193

Merged
merged 20 commits into from
May 10, 2019
Merged

[feature]: Adding a window size hook #1193

merged 20 commits into from
May 10, 2019

Conversation

sirugh
Copy link
Contributor

@sirugh sirugh commented May 2, 2019

Description

I added a window size hook so that components that need to do something based on window size (recalc/rerender/etc) can do so without having to reimplement the same functionality over and over.

I refactored the Thumbnail component to use the hook in determining whether or not to render the image.

Related Issue

Closes #1192 .

Verification Steps

  1. Open the app using chrome dev tools and set your display to "iPad" in portrait mode.
  2. Navigate to a PDP and see that no thumbnails are requested.
  3. Turn the ipad to landscape mode
  4. See that thumbnails are requested (240px image).

How Have YOU Tested this?

Above verification steps.

Screenshots / Screen Captures (if appropriate):

Proposed Labels for Change Type/Package

  • major (e.g x.0.0 - a breaking change) * ONLY MAJOR BECAUSE useDocumentListener -> useEventListener
  • minor (e.g 0.x.0 - a backwards compatible addition)
  • patch (e.g 0.0.x - a bug fix)

Checklist:

  • I have updated the documentation accordingly, if necessary.
  • I have added tests to cover my changes, if necessary.

@vercel
Copy link

vercel bot commented May 2, 2019

This pull request is automatically deployed with Now.
To access deployments, click Details below or on the icon next to each push.

Latest deployment for this branch: https://venia-git-windowsizehook.magento-research1.now.sh

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 76.907% when pulling a2f6c9c on window_size_hook into 1f70740 on develop.

@sirugh sirugh requested a review from jimbo May 2, 2019 20:55
@sirugh sirugh unassigned jimbo May 2, 2019
@@ -2,7 +2,7 @@ import React, { Component } from 'react';

import getDisplayName from 'src/util/getDisplayName';

const merge = (...args) => Object.assign({}, ...args);
export const mergeClasses = (...args) => Object.assign({}, ...args);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another thing taken from #1078

Copy link
Contributor

@jimbo jimbo left a comment

Choose a reason for hiding this comment

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

Nice work, this is looking good now. Few minor changes to make and we can merge this.

  • Consider renaming the component to just WindowSize.
  • Export the component and useWindowSize from index.js in peregrine.
  • Update the import statements accordingly.

@sirugh
Copy link
Contributor Author

sirugh commented May 6, 2019

Consider renaming the component to just WindowSize.

Should it remain in the hooks folder?

@sirugh
Copy link
Contributor Author

sirugh commented May 6, 2019

Oh and it seems like this will break a lot of tests unless we add a fake WindowSize context to the test runner root. I'll look into that.

jimbo
jimbo previously approved these changes May 10, 2019
@dpatil-magento
Copy link
Contributor

QA Pass.

Copy link
Contributor

@supernova-at supernova-at left a comment

Choose a reason for hiding this comment

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

Removal of the test.only then 👍

createTestInstance(
<WindowSizeContextProvider>
<Component />
</WindowSizeContextProvider>
Copy link
Contributor

Choose a reason for hiding this comment

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

Excuse my lack of education on hooks but I thought part of the idea was that you didn't have to rely on context like this.

Why doesn't it work for Component to just useWindowSize directly?

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay nevermind, I just reviewed the actual useWindowSize.js file. The reason is because we don't want to add duplicate event listeners, right?

If so, 👍 but it does seem like this pattern could lead to many top-level context wrappers in the future. I'm cool solving that problem if/when we get there though.

Copy link
Contributor

Choose a reason for hiding this comment

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

If so, 👍 but it does seem like this pattern could lead to many top-level context wrappers in the future. I'm cool solving that problem if/when we get there though.

Yes, it will ideally lead to that. It's like Redux without the slicing.

jimbo
jimbo previously approved these changes May 10, 2019
jimbo
jimbo previously approved these changes May 10, 2019
@dpatil-magento dpatil-magento merged commit 29cba0c into develop May 10, 2019
@sirugh sirugh added the version: Major This changeset includes incompatible API changes and its release necessitates a Major version bump. label May 24, 2019
@sirugh
Copy link
Contributor Author

sirugh commented May 24, 2019

This change renames the peregrine useDocumentListener which is a public API. Therefor major is required.

@sirugh sirugh deleted the window_size_hook branch May 24, 2019 14:12
@jimbo jimbo mentioned this pull request Jul 15, 2019
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
version: Major This changeset includes incompatible API changes and its release necessitates a Major version bump.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feature]: A window size hook!
6 participants