[w3c/payment-handler] Registration example accesses `registration` before it is defined (#200)

In the [registration example](https://www.w3.org/TR/payment-handler/#register-example) the service worker `registration` variable is accessed before it is defined. I recommend moving the registration retrieval and `paymentManager` feature check to the top of the method:

```js
button.addEventListener("click", async() => {
  const { registration } =
    await navigator.serviceWorker.register('/sw.js');
  if (!registration.paymentManager) {
    return; // not supported, so bail out.
  }

  const permission =
    await navigator.permissions.query({ name: "paymenthandler" });
  switch (permission) {
    case "denied":
      return;
    case "prompt":
      const result = await registration.paymentManager.requestPermission();
      if (result !== "granted") {
        return;
      }
      break;
  }

  // Excellent, we got it! Let's now set up the user's cards.
  await addInstruments(registration);
}, { once: true });
```

-- 
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/payment-handler/issues/200

Received on Wednesday, 9 August 2017 15:54:45 UTC