Re: Supporting Scoped Selectors in Selectors API 2

Lachlan Hunt wrote:
> Anne van Kesteren wrote:
>>
>> I do not think it is as complex as you make it out to be (especially for
>> the >90% case) and changing Selectors syntax has at least as much
>> additional cognitive load if not more if you ask me.
> 
> Well, that's not true, based on the fact that thousands of authors using 
> JS libraries seem to be having absolutely no trouble with the special 
> syntax and many find the results to be rather intuitive.  Even fantasai 
> claimed earlier in this thread [1] that the results would be more 
> intuitive, despite subsequently objecting to the essential processing 
> requirements that would achieve those results.  So your claim is 
> demonstrably false.

Mainly, I was objecting to how you were attempting to address those
requirements. The fact that querySelector does selector matching against
the whole tree but only returns results within the element is, yes, it's
confusing, and an API that scoped both the selector and the results would
be more intuitive. IMHO.

I agree with Anne that altering Selectors' core syntax is not worth it
here.

> But I believe I have found a way to make even more intuitive without 
> breaking anyone's expectations.
> 
> I removed the syntactic flag from the scoped selector string and 
> introduced scoped methods instead.
> 
> When those methods are used, for each selector in the group, if the 
> first sequence of simple selectors contains :reference, then no special 
> processing is performed.  Otherwise, if it begins with a sequence of 
> simple selectors that doesn't contain :reference, then :reference 
> followed by a descendant combinator is inserted.  Otherwise, if it 
> begins with a combinator (>, + or ~), then :reference is inserted.
> 
> For example,
> 
> "div div" becomes ":reference div div"
> "+p" becomes ":reference+p"
> ":reference>p" is unchanged.
> 
> This allows authors to be explicit if they don't like the shorthand 
> syntax, while still allowing the shorthand for those that do.

This works for me, assuming the :reference detection is from a full
selector parse and not from any kind of string matching.

I have a slight preference for
   a) :scope instead of :reference
   b) Requiring :scope when there's an explicit combinator so as not
      to present incomplete selector fragments.
a) is more important to me

Tab, what do you think?

~fantasai

Received on Tuesday, 29 September 2009 18:05:48 UTC