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

Missing Support for addEventListener/removeEventListener #86

Open
DaleSeo opened this issue Nov 11, 2020 · 4 comments
Open

Missing Support for addEventListener/removeEventListener #86

DaleSeo opened this issue Nov 11, 2020 · 4 comments

Comments

@DaleSeo
Copy link

DaleSeo commented Nov 11, 2020

The addListener and removeListener methods of MediaQueryList are deprecated and using them now causes linting errors as seen below.

image

I'd like to request adding support for the addEventListener and removeEventListener methods so that they can be used instead as recommended on MDN.

This method exists primarily for backward compatibility; if possible, you should instead use addEventListener() to watch for the change event.

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

@paulirish
Copy link
Owner

spec text here: https://drafts.csswg.org/cssom-view/#dom-mediaquerylist-addlistener

it looks like this is not technically deprecated, but it's just the old n busted legacy way of doing things.

now the MQList implements EventTarget so yeah, using that with the change event is the way to go.

@paulirish
Copy link
Owner

i started implementing this.. but... backing up..

matchMedia has been implemented in browsers for years. I can't see why you'd need a polyfill for it.

addEventListener support is everywhere too. it was added recently in safari 14 but i imagine that's already well distributed enough that you don't need to polyfill this either..

(basically it seems more sensible to just deprecate this polyfill and say it's no longer needed... wdyt?)

@DaleSeo
Copy link
Author

DaleSeo commented Nov 12, 2020

@paulirish Thanks a lot for looking at this.

I needed a polyfill for matchMedia to write server-side unit tests (using Jest) for a React component that makes use of matchMedia.
Your question makes me think that this polyfill library might be only meant for browsers and doesn't really work for Node.js. 😅

@PupoSDC
Copy link

PupoSDC commented Nov 19, 2020

Hi @paulirish

Same situation as @DaleSeo, until JSDom adds matchMedia, your polyfill is the only way to go when writing unit tests in jest :)

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

3 participants