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

Re: FileList (and other Array-like types)

From: Robin Berjon <robin@w3.org>
Date: Thu, 30 May 2013 11:41:40 +0200
Message-ID: <51A71ED4.5090509@w3.org>
To: Jonas Sicking <jonas@sicking.cc>
CC: public-script-coord@w3.org, Arun Ranganathan <arun@mozilla.com>, Boris Zbarsky <bzbarsky@mit.edu>, Anne van Kesteren <annevk@annevk.nl>
Hi Jonas,

On 30/05/2013 05:34 , Jonas Sicking wrote:
> There are two contexts where FileList is currently used:
>
> 1. In read-only situations. For example, in the drag'n'drop related
> APIs, we want to expose a list of files that the user dropped on a
> webpage. However ideally that list shouldn't be modifyable since the
> rest of the API which indicates what the user dragged is readonly.
>
> 2. In read-write situations. For the HTMLInputElement.files property, we
> should ideally permit doing something like "element.files = [blob1,
> blob2, blob3]".

This is not a WebIDL thing, but I would really expect (or at least want) 
the platform to be consistent whenever it hands me a list of files.

Imagine a simple scenario: I invite the user to provide my app with 
files, and I expose that as both a file input and a drop zone (which is 
a common approach). This gives me a list of files, which I want to 
render on some pane, while allowing the user to remove files from that 
list (think attachment area in a mail compose UI).

If you give me arrays that behave differently for pick and for drop, 
you're not being very nice. And if those arrays don't behave like JS 
arrays, you're not being very nice. This includes mutating them, and 
behaving sanely in the face of mutation.

> A) Make myInputElement.files return a frozen array. I.e. forbid
> .push-ing anything.
> B) Make myInputElement.files not return a JS-Array.
> C) Make myInputElement.files.push(5) allow the value to be pushed and
> silently ignored.
> D) Make myInputElement.files.push(5) allow the value to be pushed and
> but make the Object.observe hook remove the value.
>
> I'm partial to A myself.

I'm very partial to C. The 5 should get pushed onto the array, and 
whenever I look there in future it should still be right there, but any 
control that is reflecting the status of that array should just ignore it.

> Do JS libraries elsewhere return Array
> objects and then let the caller mutate that array as a way to pass
> information to the library?

All the libraries that do data binding (e.g. Angular, KnockOut) will do 
something like that.

-- 
Robin Berjon - http://berjon.com/ - @robinberjon
Received on Thursday, 30 May 2013 09:41:53 UTC

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