W3C home > Mailing lists > Public > www-dom@w3.org > July to September 2013

Re: [DOM4] Short and Efficent DOM Traversal

From: Ojan Vafai <ojan@chromium.org>
Date: Sat, 27 Jul 2013 19:22:51 -0700
Message-ID: <CANMdWTtZhnOJzbEVzqHCDhFa=431WGboe6-hLSARjtpeTPKt_g@mail.gmail.com>
To: François REMY <francois.remy.dev@outlook.com>
Cc: DOM WG <www-dom@w3.org>, "public-webapps@w3.org" <public-webapps@w3.org>
An alternate proposal:
What I like about my proposal is that it can be generalized to anything
that returns a Sequence<Node> and also is just less awkward than the
TreeWalker/NodeIterator interfaces.

On Sat, Jul 27, 2013 at 6:33 PM, François REMY <
francois.remy.dev@outlook.com> wrote:

> *TL/DR*: CSS Selectors represent the most commonly used way to perform
> search in the DOM. But, until now, you’ve to choose between using CSS
> (querySelectorAll) or doing incremental search (createTreeWalker). I think
> we should try to fix that.
> The proposal here would be to accept CSS selectors in replacement to the
> existing whatToShow flags {which are difficult to use and not entirely
> satisfying}, i.e. overloading the createTreeWalker/createNodeIterator
> functions to take a CSS Selector in the form of a string as a second
> parameter.
> var tw = document.createTreeWalker(document.body, “ul.menu > li”);
> while(tw.nextNode()) {
>    if(...) break;
>    ...
> }
> *Advantages:*
>    - It’s much faster than to use a javascript function as a filter that
>    would call again the browser stack to find out whether a CSS selector match
>    or not a specific element
>    - We do not loose the ability to provide a more complex piece of
>    javascript if we really need it, but we reduced the cases where we need one.
>    - It’s less code to write (CSS is more efficient than any piece of JS)
>    - It allows getting rid of the long named constants nobody likes to use
> In addition, it would open huge optimization opportunities for the browser
> (like skipping siblings that look similar, not entering into descendants if
> it’s known a certain css class is not present among them, reusing cached
> lists of elements matching a selector, or whatever).
> Thougths?
Received on Sunday, 28 July 2013 02:29:39 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 22:37:03 UTC