Re: why not MediaQueryList.onchange

On Wed, Apr 16, 2014 at 1:10 PM, L. David Baron <> 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