W3C home > Mailing lists > Public > public-script-coord@w3.org > April to June 2013

Re: Guidance on using sequences and arrays

From: Marcos Caceres <w3c@marcosc.com>
Date: Wed, 26 Jun 2013 16:33:24 +0100
To: Domenic Denicola <domenic@domenicdenicola.com>
Cc: Boris Zbarsky <bzbarsky@mit.edu>, "public-script-coord@w3.org" <public-script-coord@w3.org>
Message-ID: <9B63AFE3D3DE4F23BE644EC7E43E7652@marcosc.com>



On Wednesday, June 26, 2013 at 4:23 PM, Domenic Denicola wrote:

> From: Boris Zbarsky [mailto:bzbarsky@MIT.EDU]
>  
> > On 6/26/13 11:00 AM, Marcos Caceres wrote:
> > > > As in get notified when it changes? Or as in always see whatever the
> > > > state is now as opposed to what it was then?
> > >  
> > >  
> > >  
> > > Yes, get notified when it changes.
> >  
> > OK, that tells you nothing about array vs sequence. As in, when the notification happens you could re-examine the object you already have, or you could getCalls() to get a new sequence, depending on whether the object you have mutates itself.
>  
> This is actually a really important point. `getCalls()` returning a fresh, but mutable, array seems much more reasonable than a `calls` property that (a) cannot be messed with by script; (b) changes out from under you due to C++ magic.
I'm trying to limit the magic as much as possible by not allowing the array to change at random moments in time (only on turn of the event loop… not sure if that helps).  
>  Unfortunately that does kill any hopes of using `Object.observe` since there's no single object you can observe.

Agree. I was also thinking that it was nicer to have a dev mutable array, so one can pop, push, or whatever as needed for any particular case.  

> I think if you contemplated how to implement this in JavaScript there's not much else that would make sense. (Could be wrong, though!)

Agreed. I'm also working on a JS implementation [1], so you are right that a "read only array" would kinda screw me there.  
> (On second thought, I suppose a two-layered system like promises have, where the creator retains modification rights but the user cannot mess with it, would work. But that would definitely not be array-like in behavior, and would need to be implemented using proxies, so, kinda weird.)

Yeah, I don't want to go there unless I have to :)

[1] http://github.com/marcoscaceres/teleprolly
--  
Marcos Caceres
Received on Wednesday, 26 June 2013 15:33:55 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 21:37:49 UTC