W3C home > Mailing lists > Public > www-style@w3.org > April 2014

Re: why not MediaQueryList.onchange

From: Elliott Sprehn <esprehn@gmail.com>
Date: Wed, 16 Apr 2014 15:21:51 -0400
Message-ID: <CAPJYB1jfsBHcT17p=68GyXs3sOsejp7c523q0yK1VG82Hcb81g@mail.gmail.com>
To: "L. David Baron" <dbaron@dbaron.org>
Cc: Boris Zbarsky <bzbarsky@mit.edu>, "Tab Atkins Jr." <jackalmage@gmail.com>, www-style list <www-style@w3.org>
On Wed, Apr 16, 2014 at 1:10 PM, L. David Baron <dbaron@dbaron.org> wrote:

> On Wednesday 2014-04-09 17:45 -0700, Elliott Sprehn wrote:
> > Please do change this to fire a "change" event. The current semantics
> > involves a bunch of special logic to deal with copying the handlers and
> not
> > notifying new handlers that are added inside dispatch (across all
> > MediaLists which is far different than events). Gecko has that logic too,
> > and it's messy.
>
> I don't think we'd get rid of that logic if we switched to events;
> we'd still want to fire the events at the end of the internal
> processing rather than having to worry about what happens if we call
> out to JS in the middle of it.  And that's all it's really doing.
>

That's not the part I mean, right now if inside a listener on MediaList A
you add a listener on MediaList B it won't get called because Gecko is
batching up the listeners as it evals the queries. That's actually what the
spec says to do, but it's silly to reinvent event listeners this way with
the subtle difference.

If we switched to events you wouldn't need that collection of listeners
anymore, just copy the set of MediaLists at the start:

lists = copy of mediaLists.
for each list in lists:
  eval media query of list.
for each list in lists:
  if list is dirty:
    dispatch change event on list.

- E
Received on Wednesday, 16 April 2014 19:23:00 UTC

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