Re: [w3c/browser-payment-api] Use navigator.payments singleton, factory method, or PaymentRequest constructor (#16)

I've spent some time trying to change the proposals here into a pull request that I can live with but after looking at a couple of options I'm not currently a supporter of this change.

One goal of the current design is that using the constructor signifies lightweight object creation with no processing other than synchronous validation of the arguments. This means you can construct a `PaymentRequest` whenever you want and it's just an object in memory. If you choose then you can attach event handlers either using `EventTarget.addEventListener()` or using the function attributes on the object. Nothing really happens until you call `show()` and at this point you get a promise and asynchronous processing happens on the arguments passed in.

Calling `navigator.payments.request` suggests that you are actually making the request. In fact, [one of the proposals above](https://github.com/w3c/browser-payment-api/issues/16#issuecomment-217269345) does return the promise that `show()` gives you so it appears to be combining the constructor and `show()` methods.  Since there is no way to synchronously get the `PaymentRequest object`, you can't add event listeners without there being a risk of missing events.

I toyed with the idea of using `navigator.payments.createRequest` but even this name could easily be confused with make request and doesn't signify the only the construction of an in memory object.

We have lots of constructors in our type system today. Fairly recently, Events moved away from using the `initEvent()` method to using a constructor. Modern specs like WebRTC, Web Notifications, and Fetch use constructors so it's not necessarily considered a pattern to avoid. This is an approach that developers are used to and generally signifies creating an object with no processing, which is what we want.

With this in mind I propose that we keep the current API, at least for now until we learn more.



---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/browser-payment-api/issues/16#issuecomment-219497721

Received on Monday, 16 May 2016 18:01:36 UTC