Re: [selectors-api] comments on Selectors API Level 2

On Wednesday 20 January 2010, Andrew Fedoniouk wrote:
> Daniel Glazman wrote:
> >    I would recommend dropping the pseudo-class :scope and make a
> > simpler model where a fictional :scope pseudo-class and a
> > descendant combinator are prepended to all selectors passed as the
> > argument of the corresponding APIs.
>
> There are cases where you will need to match only immediate children
> using such queryScopedSelector() function.
>
> Possible solutions:
>
> element.$("> .child");
> element.$(":root > .child");
>
> :root here is the element itself - root of the lookup.
>
> BTW: the name of the function queryScopedSelectorAll() has at least
> one technical and one grammatical error. Can we rename it somehow?

If I read the WD correctly, not only ':scope' is redundant, but 
queryScopedSelector() and queryScopedSelectorAll() are, too.

So I'd suggest:

1) Drop the keyword ':scope'.

  - It's redundant. The spec says that everywhere you are allowed to use
    it, you can also omit it and it will be implied. So why not omit it?
  - It's confusing. You are not allowed to use it everywhere, so it is
    an opportunity to make mistakes.
  - It makes the syntax that querySelector() accepts almost the same but
    not quite as the selectors syntax that CSS allows. Better to either
    have a completely different syntax or one that is exactly the same,
    otherwise you just invite errors.

2) Drop queryScopedSelector() and queryScopedSelectorAll(). It is 
trivially easy to replace a call to queryScopedSelector() by a call to 
querySelector(). All you have to do is replace

    e.queryScopedSelector(x)
by
    e.ownerDocument.querySelector(x)

where e is an Element. And for documents d the functions are even 
exactly the same: d.queryScopedSelector(x) == d.querySelector(x) for 
all documents d and selectors x.

  - Smaller API means less to implement,
  - less to test,
  - less to learn for users.
  - less variation in programs,
  - thus easier to understand other people's code.


Somebody somewhere else was wondering about the selector ':root + *'. I 
would say it's a valid selector that just happens to never match 
anything, because a tree by definition has only one root. The same 
holds for selectors like '#foo #foo' (valid, but guaranteed to return 
nothing, because IDs are by definition unique), '*:first-child:even' 
(the first child is obviously odd, not even), and ':root:first-child' 
(the root is not a child of anything).

Here are some examples of relations that always hold. (Assume e is an 
element != NULL.)

    e.querySelector("*") == e.querySelector(":root")
    e.querySelector("*") == e
    e.querySelector(":root + *") == NULL
    e.querySelector(":root:first-child") == NULL
    e.querySelector("* *") == e.querySelector(":root > :first-child")
    e.querySelector(":odd") == e.querySelector(":root > :first-child")



Bert
-- 
  Bert Bos                                ( W 3 C ) http://www.w3.org/
  http://www.w3.org/people/bos                               W3C/ERCIM
  bert@w3.org                             2004 Rt des Lucioles / BP 93
  +33 (0)4 92 38 76 92            06902 Sophia Antipolis Cedex, France

Received on Thursday, 21 January 2010 16:12:33 UTC