Re: Proposal to switch to an object-literal Intent constructor

Object literal ftw, though we should remove the old constructor.  It
unnecessarily adds to the footprint of the API and can cause developer
confusion ("Which constructor should I be using?", etc.)

James

On Wed, Mar 28, 2012 at 7:04 PM, Charles Pritchard <chuck@jumis.com> wrote:

> It's certainly in vogue.
>
> I prefer to have both methods. The direction of the HTML editor and assist
> is definitely to go solely with dictionary notation. I just find it to be
> verbose at times.
>
>
>
> On Mar 28, 2012, at 4:50 PM, Greg Billock <gbillock@google.com> wrote:
>
> > Hi everyone!
> >
> > I'll be sending several emails in the next few days following up to
> > discussions we had at the F2F meeting. One proposal is adding an
> > object literal constructor for the Intent object. This object literal
> > will be convenient for adding other types of constructor arguments
> > which we know we will want (defaults, explicit intents, perhaps even
> > more exotic varieties to be discovered later).
> >
> > My proposal is to replace the existing signature with the object
> > literal constructor.
> >
> > Current:
> >
> > [Constructor(in string action, in string type, in optional any data,
> > in optional sequence<Transferable> transferList, in optional
> > dictionary<string> extraData) raises DOMException]
> > interface Intent {
> >  readonly attribute DOMString     action;
> >  readonly attribute DOMString     type;
> >  readonly attribute any           data;
> >  readonly attribute MessagePort[] ports;
> >  string getExtra (DOMString key);
> >  void   postResult (any data, optional  sequence);
> >  void   postFailure (any data);
> > };
> >
> >
> > Proposed change:
> >
> > dictionary IntentParameters {
> > DOMString action;
> > DOMString type;
> > any data;
> > sequence<Transferable> transfer;
> > dictionary<string> extras;
> > }
> >
> > [Constructor(in IntentParameters parameters)]
> > interface Intent {
> >  readonly attribute DOMString     action;
> >  readonly attribute DOMString     type;
> >  readonly attribute any           data;
> >  readonly attribute MessagePort[] ports;
> >  string getExtra (DOMString key);
> >  void   postResult (any data, optional  sequence);
> >  void   postFailure (any data);
> > };
> >
> > When using the object literal constructor, the "action" and "type"
> > members are required, all others are optional.
> >
> > (Aside to Robin: is there a convention for marking required/optional
> > dictionary fields? I saw a "type? name" syntax on IndexedDB. Is that
> > the standard?)
> >
> > The proposal removes the constructor without the object literal:
> >
> > [Constructor(in string action, in string type, in optional any data,
> > in optional sequence<Transferable> transferList) raises DOMException]
> >
> > What do you think? Would it be an advantage to keep this constructor
> > to keep the simple use cases simpler? The difference is this:
> >
> > var x = new Intent("http://webintents.org/view", "schema.org/Person",
> person);
> > vs
> > var x = new Intent({"action":"http://webintents.org/view",
> >                    "type":"schema.org/Person",
> >                    "data":person});
> >
> > Is the shorter first form worth the addition of the extra constructor
> > signature? Named arguments are pretty nice...
> >
>
>

Received on Sunday, 1 April 2012 23:47:07 UTC