-
Notifications
You must be signed in to change notification settings - Fork 686
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
Conversation
This pull request is automatically deployed with Now. Latest deployment for this branch: https://venia-git-windowsizehook.magento-research1.now.sh |
@@ -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); |
There was a problem hiding this comment.
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
packages/venia-concept/src/components/ProductImageCarousel/thumbnail.js
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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
fromindex.js
in peregrine. - Update the import statements accordingly.
Should it remain in the |
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. |
QA Pass. |
There was a problem hiding this 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> |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
packages/venia-concept/src/components/ProductImageCarousel/__tests__/carousel.spec.js
Outdated
Show resolved
Hide resolved
This change renames the peregrine |
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
How Have YOU Tested this?
Above verification steps.
Screenshots / Screen Captures (if appropriate):
Proposed Labels for Change Type/Package
useDocumentListener
->useEventListener
Checklist: