Re: Guidance on using sequences and arrays

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 :)

Marcos Caceres

Received on Wednesday, 26 June 2013 15:33:55 UTC