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

Use MediaQueryList.addListener(func) over window.addListener('resize', func) #1

Open
elliottregan opened this issue Aug 8, 2018 · 5 comments
Assignees

Comments

@elliottregan
Copy link

There is a better API for handling media query changes:

https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryList/addListener

@PxyUp
Copy link
Owner

PxyUp commented Aug 8, 2018

In this case we need create all observers on all breakpoints, and after that create subscribers on each. When using resize event u just, have only one observer on window resize event.

@PxyUp PxyUp closed this as completed Aug 8, 2018
@elliottregan
Copy link
Author

You might want to optionally throttle the resize event handler, then. Your code will be called every time the browser resizes a pixel, which can slow things down. http://bencentra.com/code/2015/02/27/optimizing-window-resize.html

MediaQueryList.addListener(func) solves this by not firing on every resize, but only when the breakpoint changes.

@PxyUp PxyUp self-assigned this Sep 27, 2018
@alejandroiglesias
Copy link

MediaQueryList listeners are much more performant than listening to the window resize event.

@john-hix
Copy link

john-hix commented Dec 3, 2020

Hi. Thanks for publishing this package. It doesn't seem like this issue was resolved. Would you like help implementing a MediaQueryList listener?

@PxyUp
Copy link
Owner

PxyUp commented Dec 3, 2020

Hi, will be good

Hi. Thanks for publishing this package. It doesn't seem like this issue was resolved. Would you like help implementing a MediaQueryList listener?

@PxyUp PxyUp reopened this Dec 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants