W3C home > Mailing lists > Public > www-style@w3.org > September 2009

Re: Supporting Scoped Selectors in Selectors API 2

From: Tab Atkins Jr. <jackalmage@gmail.com>
Date: Mon, 28 Sep 2009 17:09:16 -0500
Message-ID: <dd0fbad0909281509h233844a4q30e35b01c0ca2ee3@mail.gmail.com>
To: Lachlan Hunt <lachlan.hunt@lachy.id.au>
Cc: fantasai <fantasai.lists@inkedblade.net>, www-style <www-style@w3.org>
On Mon, Sep 28, 2009 at 3:59 PM, Lachlan Hunt <lachlan.hunt@lachy.id.au> wrote:
> fantasai wrote:
>> I will also note that the use of ! has been proposed for other things,
>> and I would strongly prefer if your API did not introduce any new
>> punctuation into the Selectors syntax.
>
> The point is that in order to solve the problem, we need some kind of
> indicator to say that this is a scoped selector.

The problem with it as written, though, is that you're *only* using it
in a single case, when you're trying to do a scoped selector that
starts with the descendant combinator.  This makes it very likely that
it will be overlooked, and authors will accidentally forget to use it
when needed.  Even worse, it's likely that they won't ever notice it
breaking from the wrong behavior, since the difference between scoped
and regular querySelector is relatively minor.

That's why I suggested, if you required a flag, to make it required in
*all* cases, even when it's implicitly obvious from the selector
string.  This way it becomes an automatic talisman that authors insert
without thinking.  It's still crufty, but it's more likely to work
without relatively subtle bugs creeping into pages by accident.  This
is not my preferred solution, though.

> The final option is to simply forgo the special parsing entirely and require
> authors and javascript libraries to insert explicit :reference
> pseudo-classes at the beginning of each selector,

Given the constraints from the existing design of querySelector, this
is my preferred solution*.  Switching to a shorter pseudoclass name
than "reference" would make this better.  (I think "reference" is fine
in general, it's just too long to be practically for use everywhere.)

> but we'd still need to
> find some way of addressing the sibling element problem, and that would
> require authors to use a more complicated approach like:
>
> elm.parentNode.querySelectorAll(":reference+p", elm);

I don't see why.  You are already proposing that certain things in the
query string implicitly trigger the new scoped behavior (the presence
of a combinator at the start of a selector, or the ! symbol at the
start).  Why not have :reference do that instead?


*Actually, my preferred solution is to just have a function that does
scoped stuff automatically, since that is much more intuitive and in
line with how javascript libraries do things already.  I'm not sure
why we needed two separate functions either when a simple [0] tacked
to the end of the *All call would work.  Ideally we'd have a single
selector() function that is automatically scoped and returns an array
of results.

~TJ
Received on Monday, 28 September 2009 22:10:23 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 17:20:21 GMT