Re: Clarification on "live NodeList"

Boris Zbarsky wrote:
> Andrew Fedoniouk wrote:
>> I am not sure I understand how you would return the same instance
>> of NodeList for different elements that were used to invoke 
>> getElementsByName() with.
>
> Oh, for different elements, sure.  But then they would be observing 
> mutations in different parts of the document, too...
>
> In any case, from what I've seen calling getElementsByTagName (which I 
> assume you meant, since getElementsByName only exists on documents) on 
> elements is a rare case.
Yes, that is getElementsByTagName(). And getElementsByClassName is there 
too  (according to Mozilla docs it can be applied to arbitrary element)
>
>> To be honest that reasoning sounds like "to be compatible with design 
>> flaws of our forefathers".
>
> No, it's "to be compatible with existings scripts that assume this 
> behavior".
Do you know any existing code that relies on liveness of NodeLists?

In any case liveness of NodeLists is useless if NodeList has no events 
like NodeList.onSetChanged = function()

And iterations on live collections like this:

var live = element.getElementsByClassName(...);
var live_length = live.length;
for( var i = 0; i < live_length; ++i )
{
   .... some code that may cause 'live' to change ....
}

is almost always source of problems as there is almost *no way* to 
handle this appropriately (without the event reporting
what and where was changed).

In cases then body of the loop is not mutating the DOM:
for( var i = 0; i < live_length; ++i )
{
   .... some reas-only code  ....
}
you will not need liveness of NodeList's at all.

So is my question above: do you have any examples of code that uses 
exactly [Live]NodeList?

>
>> Back to the problem: I do not see what would be a problem to declare
>>  getElementsByClassName() & friends as returning something like
>> StaticNodeList (: public NodeList) as one wise person put here:
>>
>> http://dev.w3.org/2006/webapi/selectors-api/draft/selectors-api.htm#staticnodelist 
>
>
> It'd break existing pages.  So it's a non-starter.
Just curious....

Boris, do you know any real page that will stop working if NodeList will 
be replaced by StaticNodeList in getElementsByTagName(), 
getElementsByClassName() or getElementsBySelector (...CSS selector...)?
>
> -Boris
>
>
--
Andrew Fedoniouk.

http://terrainformatica.com

Received on Friday, 10 July 2009 18:06:05 UTC