Re: document.body.appendChild(promiseForNode)

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