Re: Guidance on using sequences and arrays

On Wednesday, June 26, 2013 at 2:44 PM, Boris Zbarsky wrote:

> On 6/26/13 6:15 AM, Marcos Caceres wrote:
> > What I'm confused about is what does "readonly" mean in the above. Clearly, it means that the reference of the array in the attribute can't be changed - but what about the content of the array?
> 
> Undefined. There are three different kinds of Call[] defined in WebIDL: 
> readonly, fixed-length, and writable. There is no way to differentiate 
> between them in IDL (a bug, imo), so you have to say in prose what kind 
> yours is.


I also agree that this is a bug. It would be nice to be able to express this directly in WebIDL through an extended attribute or something. 

> > Can a developer do the following:
> > 
> > telephony.calls.pop();
> > telephony.calls.push(SomeOldCallObj);
> > 
> > If so, that would obviously be bad.
> 
> Then you presumably want a readonly array.
Yes, I had missed this in the spec:
http://dev.w3.org/2006/webapi/WebIDL/#dfn-read-only-array.
 
> > Would it then be appropriate to change the calls attribute to a sequence (i.e., sequence<Call> getCalls())?
> 
> Here's the right litmus test for this. If a developer does:
> 
> myCalls = telephonymanager.calls;
> 
> Do we then want them to see the contents of myCalls change as the set of 
> calls the UA manages changes?

Yes, the developer needs to be able to monitor changes to the array. 

Small question: there is an event defined for monitoring changes to the Calls array in the API ("callschanged" and corresponding "oncallschanged" event handler attribute) which I think kinda sucks (hence my previous email asking about using Object.observe) - I wanted to get rid of the event. Is there some way of monitoring this array without an event? Object.observe(telephony.calls, function(details){...}) feels really right here. 
> If so, you want a readonly Call[] here.

ok, cool. That's super helpful, thank you!  
> 
> If not, you want a sequence. Which behavior you want is "just" an API 
> design decision, as far as I can tell

So, for now, I will keep it as is, but put the write prose into the spec about it being a "read only array".  

Thanks again! 

Received on Wednesday, 26 June 2013 14:39:46 UTC