W3C home > Mailing lists > Public > www-style@w3.org > June 2012

Re: [CSSOM View] MediaQueryList as EventTarget

From: Dean Jackson <dino@apple.com>
Date: Fri, 15 Jun 2012 10:55:15 -0700
Cc: www-style list <www-style@w3.org>
Message-id: <487A0B47-09F4-44D6-88E2-E289BBA6FF38@apple.com>
To: "L. David Baron" <dbaron@dbaron.org>

On 14/06/2012, at 8:39 PM, L. David Baron <dbaron@dbaron.org> wrote:

> On Thursday 2012-06-14 18:25 -0700, Dean Jackson wrote:
>> The MediaQueryList interface has addListener and removeListener
>> methods, that each take a MediaQueryListListener (which is a
>> pretty cool name when you think about it).
>> MediaQueryListListener has a single handleChange() method.
> Which is marked [Callback] so that the name should basically never
> show up.

Sorry, I need to do my homework because I didn't even know what
that meant :)

>> Is there a good reason why MediaQueryList isn't just an
>> EventTarget? It makes more sense to me, and would allow you to
>> have a single controller object to implement handleEvent for all
>> your code. As it currently stands, it is a weird handleChange
>> method.
> I seem to recall a previous discussion of replacing these
> notifications with events, but I think it was started by a
> suggestion that the window or the document be the target, which
> makes this rather more difficult.

My request was triggered by the fact that the EventListener interface
is extremely handy if you want a central piece of code to process
incoming events (typical MVC).

For example a controller object that has a method handleEvent. You pass
the controller as the event listener. The handleEvent method is a big
switch statement that checks the eventType (and other stuff) working
out what to do. It's much much better than adding anonymous functions
(which make it hard to remove as listeners later).

The fact that the MediaQueryListListener has a method with a different
name makes this approach more complex, even though you would typically
treat this situation as something your controller needs to process. A
media query evaluation changing its result seems like an event to me.

>  Off the top of my head, I don't
> see a reason that the MediaQueryList couldn't be the target other
> than compatibility with the existing implementations (which I think
> include quite a few major browsers, so compatibility may be a real
> issue).

It probably is way too late to change anything here, yes.

> (Is your assumption that the events wouldn't bubble anywhere?)


Received on Friday, 15 June 2012 17:55:44 UTC

This archive was generated by hypermail 2.3.1 : Monday, 2 May 2016 14:39:00 UTC