72 messages in org.w3.public-webapiRe: ACTION-87: Selectors API
FromSent OnAttachments
Anne van KesterenFeb 25, 2006 9:11 am.htm
Daniel SchierbeckFeb 25, 2006 10:18 am 
Daniel SchierbeckFeb 25, 2006 10:23 am 
Bjoern HoehrmannFeb 25, 2006 10:43 am 
Daniel SchierbeckFeb 25, 2006 11:28 am 
Jim LeyFeb 25, 2006 11:47 am 
Ian HicksonFeb 25, 2006 3:56 pm 
Cameron McCormackFeb 25, 2006 4:46 pm 
Lachlan HuntFeb 25, 2006 4:58 pm 
Cameron McCormackFeb 25, 2006 5:00 pm 
Daniel SchierbeckFeb 25, 2006 5:24 pm 
Anne van KesterenFeb 26, 2006 2:21 am 
Cameron McCormackFeb 26, 2006 2:32 am 
Cameron McCormackFeb 26, 2006 1:03 pm 
Maciej StachowiakFeb 26, 2006 3:02 pm 
Jonas SickingFeb 28, 2006 1:57 pm 
Ian HicksonMar 6, 2006 12:33 pm 
Ian HicksonMar 6, 2006 12:35 pm 
Anne van KesterenMar 22, 2006 2:30 am 
Anne van KesterenMar 22, 2006 2:33 am 
Anne van KesterenMar 22, 2006 2:34 am 
mozerMar 22, 2006 3:15 am 
Anne van KesterenMar 22, 2006 3:58 am 
mozerMar 22, 2006 4:29 am 
Anne van KesterenMar 22, 2006 4:36 am 
Jim LeyMar 22, 2006 5:43 am 
Anne van KesterenMar 22, 2006 6:08 am 
Jim LeyMar 22, 2006 6:44 am 
Maciej StachowiakMar 22, 2006 11:16 am 
Maciej StachowiakMar 22, 2006 11:22 am 
Maciej StachowiakMar 22, 2006 11:24 am 
Robin BerjonMar 22, 2006 2:01 pm 
Maciej StachowiakMar 22, 2006 2:28 pm 
Ian HicksonMar 22, 2006 2:48 pm 
Ian HicksonMar 22, 2006 2:50 pm 
Maciej StachowiakMar 22, 2006 3:20 pm 
Jim LeyMar 22, 2006 6:16 pm 
Jim LeyMar 22, 2006 6:24 pm 
Anne van KesterenMar 23, 2006 4:27 am 
Ian HicksonMar 23, 2006 2:30 pm 
Anne van KesterenMar 25, 2006 4:36 am 
Ian HicksonMar 27, 2006 3:13 pm 
Anne van KesterenApr 3, 2006 5:45 am 
Anne van KesterenApr 3, 2006 5:51 am 
lioreanMay 12, 2006 8:49 pm 
Anne van KesterenMay 13, 2006 4:15 am 
lioreanMay 13, 2006 12:08 pm 
Anne van KesterenMay 13, 2006 12:26 pm 
lioreanMay 13, 2006 2:39 pm 
Anne van KesterenMay 14, 2006 7:20 am 
lioreanMay 14, 2006 4:21 pm 
Anne van KesterenMay 15, 2006 3:15 am 
lioreanMay 16, 2006 9:29 pm 
Anne van KesterenMay 17, 2006 5:17 am 
Lachlan HuntMay 17, 2006 6:19 am 
Anne van KesterenMay 17, 2006 6:29 am 
Jim LeyMay 17, 2006 6:35 am 
Lachlan HuntMay 17, 2006 7:02 am 
Robin BerjonMay 17, 2006 7:07 am 
Anne van KesterenMay 18, 2006 12:45 am 
Jonas SickingMay 30, 2006 3:11 pm 
Jonas SickingMay 30, 2006 3:24 pm 
Jonas SickingMay 30, 2006 3:41 pm 
Ian HicksonMay 30, 2006 3:55 pm 
Robin BerjonMay 30, 2006 4:14 pm 
Jonas SickingMay 30, 2006 5:56 pm 
Anne van KesterenJun 5, 2006 2:46 am 
Anne van KesterenJun 5, 2006 2:49 am 
Jonas SickingJun 5, 2006 12:30 pm 
Charles McCathieNevileJun 5, 2006 5:36 pm 
lioreanJun 5, 2006 6:16 pm 
Maciej StachowiakJun 5, 2006 10:40 pm 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: ACTION-87: Selectors APIActions...
From:Maciej Stachowiak (mj@apple.com)
Date:Feb 26, 2006 3:02:45 pm
List:org.w3.public-webapi

On Feb 26, 2006, at 1:04 PM, Cameron McCormack wrote:

Cameron McCormack:

As for whether these are easy to implement or not, I guess it's a matter of whether you are building on top of a CSS engine that you can't modify. The main advantage would be access to selector parsing routines.

*after thinking about it last night*

You also need code that performs the actual selections, too. This should be very similar to that which selects for the stylesheet rules anyway, though.

It's not that simple. Selectors for stylesheets are matched by examining the element when applying style, and testing what rules match. This API would require finding the elements that match a selector. The naiive way to do this is to walk the whole document and test each element for matching. But this is going to be way slower than, say, getElementById which operates in O(1) time in most browsers.

Both live lists and non-live lists have issues with being implementable efficiently. For a static list, you have to compute the whole list right away to make sure it remains static in teh face of changes. That means that even if you want only the first match you have to walk the whole document. This means that probably you want a selectSingleElement() in addition to selectElements().

Live lists have the problem that any document change forces you to recompute the list, so iterating the list while modifying the document often has O(N^2) behavior. For a subset of selectors it may be possible to avoid this through caching, and detecting exactly what changes make a difference, and putting in lots of notifications. But I think for at least some selectors this is not feasible.

I also think live lists are a confusing programming model. If you really are modifying the document while traversing the list, it is likely more annoying than helpful for the list to change. For example:

// severely buggy function removeAllDivs() { var divs = document.getElementsByTagName("divs"); for (var i = 0; i < divs.length; i++) { var div = divs[i]; div.parentNode.removeChild(div); } }

This will not remove all divs. Could you even say without thinking about it which divs it will remove?

It seems to me that, when modifying the document, you generally do not want a live list, and when not modifying the document, it doesn't matter which kind you have. Therefore I would recommend against propagating the "live list" concept in new APIs.

So, in brief: - Having an existing style system does not make it trivial to implement a DOM API to find elements by selector. - Static lists are probably more efficiently implementable than live lists. - Static lists would require a single-element version too, so you don't have to build the whole list just to get one element. - Live lists are confusing as a programming model. - Live lists suck for performance and make it easy to accidentally write O(N^2) code.

Regards, Maciej