Re: Is for...of on a live DOM node list supposed to do the right thing?

2013-11-22 Thread Jason Orendorff
On 11/22/13 8:40 AM, Benjamin Smedberg wrote:
> Is for..of on live DOM nodelists supposed to correctly iterate even
> when items are removed from the list? I have a testcase where this
> does not seem to be working correctly:
>
> http://jsfiddle.net/f8xzQ/
>
> Is there a simple way to do this correctly?

Well, there's this:
http://jsfiddle.net/f8xzQ/1/

I think those iterators should be "live", like everything else in the
DOM! I mentioned this to anyone who would listen back when I made DOM
NodeLists iterable in the dumbest possible way, and got a lot of blank
stares. Certainly no one was interested in doing the work.

It's also possible to do this using a hand-JS-coded wrapper around
document.createNodeIterator, which is "live". Maybe not in all cases.

-j

___
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform


Re: Is for...of on a live DOM node list supposed to do the right thing?

2013-11-22 Thread Boris Zbarsky

On 11/22/13 9:40 AM, Benjamin Smedberg wrote:

Is for..of on live DOM nodelists supposed to correctly iterate even when
items are removed from the list?


I believe the current behavior is identical to what would happen with an 
array here.  Consider http://jsfiddle.net/hpmHg/3/


The core issue here is that for..of iteration does NOT snapshot anything 
(unlike for..in iteration).


We could change the iterator to somehow adjust its position internally 
on DOM mutations, but defining exactly how that should work is not quite 
trivial.



Is there a simple way to do this correctly?


  for (var x of Array.from(list))

to explicitly snapshot?  Cross-browser compat might not be great so far, 
but it's not for for..of either.


-Boris
___
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform


Re: Is for...of on a live DOM node list supposed to do the right thing?

2013-11-25 Thread Anne van Kesteren
On Fri, Nov 22, 2013 at 6:00 PM, Boris Zbarsky  wrote:
>   for (var x of Array.from(list))
>
> to explicitly snapshot?  Cross-browser compat might not be great so far, but
> it's not for for..of either.

Right. And going forward we'll make sure to introduce less live lists
on the platform side. E.g. querySelector et al return static lists.
The proposed query and queryAll methods will return a subclass of
Array.


-- 
http://annevankesteren.nl/
___
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform