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

Re: document.body.appendChild(promiseForNode)

From: Tab Atkins Jr. <jackalmage@gmail.com>
Date: Mon, 2 Sep 2013 12:19:21 -0700
Message-ID: <CAAWBYDDj3Z1JzCyn+p8hbg=STrDxgEJAaMKRL7F=NV4hgHt-4w@mail.gmail.com>
To: David Bruant <bruant.d@gmail.com>
Cc: "public-script-coord@w3.org" <public-script-coord@w3.org>
On Mon, Sep 2, 2013 at 10:56 AM, David Bruant <bruant.d@gmail.com> wrote:
> Hi,
>
> I apologize in advance if this has been discussed already, I'm a bit behind
> regarding promise discussions.
>
> As far as I know, currently, standard functions that expect an object of a
> given type will throw when passed a promise. However, wouldn't it be elegant
> to do:
>
>     var dataP = getData(url1); // http GET
>     var templateP = getTemplate(url2); // http GET
>     var nodeP = Promise.every(templateP, dataP).then(compileTemplate);
>     document.body.appendChild(nodeP);

Why not instead just do:

    var dataP = getData(url1); // http GET
    var templateP = getTemplate(url2); // http GET
    var nodeP = Promise.every(templateP, dataP)
      .then(compileTemplate)
      .then(node=>document.body.appendChild(node));

?

~TJ
Received on Monday, 2 September 2013 19:20:10 UTC

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