Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated examples.md - Formatting #357

Merged
merged 1 commit into from
Apr 2, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 12 additions & 4 deletions proposals/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ For each use case we should see code that demonstrates the following, with descr
## Code Samples

<h3 id="example2">Getting permission to "handle payments"</h3>

```javascript
navigator.serviceWorker
.register('/app.js', 'https://apps.domain.net/')
Expand All @@ -44,6 +45,7 @@ navigator.serviceWorker
```

<h3 id="example31">Adding payment methods</h3>

```javascript
navigator.serviceWorker
.getRegistration('https://apps.domain.net/')
Expand All @@ -59,6 +61,7 @@ navigator.serviceWorker
```

<h3 id="example33">Updating payment methods</h3>

```javascript
navigator.serviceWorker
.getRegistration('https://apps.domain.net/')
Expand All @@ -74,7 +77,9 @@ navigator.serviceWorker
```

<h3 id="example32">Removing payment methods</h3>
```javascript

```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
```
```javascript

javascript
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
javascript

navigator.serviceWorker
.getRegistration('https://apps.domain.net/')
.then(function(registration) {
Expand All @@ -83,13 +88,15 @@ navigator.serviceWorker
```

<h3 id="example1">A service worker that has an event listener for the `onpaymentrequest` event</h3>

```javascript
self.addEventListener('paymentrequest', function (paymentrequestEvent) {
console.log("got it! " + JSON.stringify(paymentrequestEvent.data));
});
```

<h3 id="example4">Returning a response to the `onpaymentrequest` event</h3>

```javascript
self.addEventListener('paymentrequest', function (paymentrequestEvent) {
var accepted = true;
Expand All @@ -103,7 +110,9 @@ self.addEventListener('paymentrequest', function (paymentrequestEvent) {
## App Samples
<h3 id="app1">`basic-card` payment</h3>
Actual running full project [here](https://github.com/pjbazin/wapp-examples)

#### registration

```javascript
navigator.serviceWorker
.register('/app-bc.js')
Expand Down Expand Up @@ -132,6 +141,7 @@ navigator.serviceWorker
```

#### execution (app-bc.js)

```javascript
self.addEventListener('install', function(event) {
// 'install' event is fired when the SW registration is successfully completed.
Expand Down Expand Up @@ -175,6 +185,4 @@ self.addEventListener('paymentrequest', function(paymentrequestEvent) {

}));

});

```
});```