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

MediaQueryListListener should provide a MediaQueryListEvent #550

Closed
ghost opened this issue Aug 1, 2018 · 6 comments
Closed

MediaQueryListListener should provide a MediaQueryListEvent #550

ghost opened this issue Aug 1, 2018 · 6 comments

Comments

@ghost
Copy link

ghost commented Aug 1, 2018

In typescript@3.0 this was:

interface MediaQueryListListener {
    (mql: MediaQueryList): void;
}
interface MediaQueryList {
    readonly matches: boolean;
    readonly media: string;
    addListener(listener: MediaQueryListListener): void;
    removeListener(listener: MediaQueryListListener): void;
}

As of microsoft/TypeScript#25944 this is now:

interface MediaQueryList extends EventTarget {
	...
    addListener(listener: EventListenerOrEventListenerObject | null): void;
    ...
}

According to mdn this is better than before, but it could be more specific -- the event will always be a MediaQueryListEvent, but currently will just be an Event.

This affects match-media-mock on DefinitelyTyped.

@saschanaz
Copy link
Contributor

Also the addListener/removeListener pair should be marked as deprecated as now the standard add/removeEventListener is preferred.

@SteppeEagle
Copy link

Also the addListener/removeListener pair should be marked as deprecated as now the standard add/removeEventListener is preferred.

@saschanaz Where did you find that they should be deprecated?
In the standard there is no word about deprecation.
https://drafts.csswg.org/cssom-view/#dom-mediaquerylist-addlistener

@saschanaz
Copy link
Contributor

saschanaz commented Dec 28, 2018

@SteppeEagle The deprecation in the web specification means it would generate a warning message at runtime when used, and the web people now don't want to use such mechanism. They instead marks a type as "historical, only for backward compatibility" and that's what we currently refer to add @deprecated.

Per the spec the APIs are historical:

Note: This specification initially had a custom callback mechanism with addListener() and removeListener(), and the callback was invoked with the associated media query list as argument. Now the normal event mechanism is used instead. For backwards compatibility, the addListener() and removeListener() methods are basically aliases for addEventListener() and removeEventListener(), respectively, and the change event masquerades as a MediaQueryList.

@teleaziz
Copy link

This is related, angular/components#15264, Safari doesn't implement addEventListener/RemoveEventListener which leaves us no option but to use the historical APIs and redefine the MediaQueryList interface in our codebases .....

@krokofant
Copy link

@teleaziz Can't one just add a polyfill in case addEventListener doesn't exist?

@saschanaz
Copy link
Contributor

Or maybe one can just add // tslint:disable-next-line:deprecation over the specific lines.

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