Skip to content

Commit 5299eb1

Browse files
committed
Update the explainer
Signed-off-by: Zoltan Kis <[email protected]>
1 parent 5e5e51d commit 5299eb1

File tree

2 files changed

+33
-40
lines changed

2 files changed

+33
-40
lines changed

EXPLAINER.md

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,17 @@ when required, about granting access to Web NFC. It means sending and receiving
9292
info when users tap NFC devices can be done smoothly once permission is granted.
9393

9494
```js
95-
const reader = new NDEFReader();
95+
const ndef = new NDEFReader();
9696

9797
async function startScanning() {
98-
await reader.scan();
99-
reader.onreading = event => {
98+
await ndef.scan();
99+
ndef.onreading = event => {
100100
/* handle NDEF messages */
101101
};
102102
}
103103

104104
const nfcPermissionStatus = await navigator.permissions.query({ name: "nfc" });
105-
if (permissionStatus.state === "granted") {
105+
if (nfcPermissionStatus.state === "granted") {
106106
// NFC access was previously granted, so we can start NFC scanning now.
107107
startScanning();
108108
} else {
@@ -126,10 +126,10 @@ cases where the text might even be in UTF-16 do to existing real life
126126
implementations.
127127

128128
```js
129-
const reader = new NDEFReader();
129+
const ndef = new NDEFReader();
130130

131-
await reader.scan({ recordType: "example.com:smart-poster" });
132-
reader.onreading = event => {
131+
await ndef.scan({ recordType: "example.com:smart-poster" });
132+
ndef.onreading = event => {
133133
const externalRecord = event.message.records.find(
134134
record => record.type == "example.com:smart-poster"
135135
);
@@ -166,7 +166,7 @@ abortController.signal.onabort = event => {
166166
const ndef = new NDEFReader();
167167
await ndef.scan({ signal: abortController.signal });
168168

169-
await ndef.push("foo", { signal: abortController.signal });
169+
await ndef.write("foo", { signal: abortController.signal });
170170

171171
document.querySelector("#abortButton").onclick = event => {
172172
abortController.abort();
@@ -227,12 +227,10 @@ same API, and have it loaded as a separate module. People working on Web
227227
Assembly are also advocating for this patterns as it might be able to turn such
228228
globals into modules in the future, at least when accessed from WASM.
229229

230-
### Separate objects for reader/writer
230+
### Common vs separate objects for reader/writer
231231

232-
The reader and writer objects could have been merged into one single object, but
233-
as we allow multiple scans with filters to be active at the same time (maybe in
234-
multiple places/view of the app/site) then it makes more sense to be able to use
235-
separate objects.
232+
The reader and writer objects existed separately when scan filters were supported,
233+
but after filters have been abandoned, they have been merged into one single object.
236234

237235
## Considered alternatives
238236

index.html

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,7 +1105,7 @@ <h4>
11051105
</p>
11061106
<pre class="example">
11071107
const ndef = new NDEFReader();
1108-
ndef.onreading(event => console.log("We read a tag!"));
1108+
ndef.onreading = event => console.log("We read a tag!"));
11091109

11101110
function write(data, { timeout } = {}) {
11111111
return new Promise((resolve, reject) => {
@@ -2045,14 +2045,6 @@ <h2>The <dfn>record type</dfn> string</h2>
20452045
</tr>
20462046
</thead>
20472047
<tbody data-link-for="NDEFReader">
2048-
<tr>
2049-
<tr>
2050-
<td><dfn>[[\ScanAbortSignal]]</dfn></td>
2051-
<td>`undefined`</td>
2052-
<td>
2053-
The {{NDEFScanOptions}}.signal to abort the operation.
2054-
</td>
2055-
</tr>
20562048
<tr>
20572049
<td><dfn>[[\WriteOptions]]</dfn></td>
20582050
<td>`null`</td>
@@ -3443,30 +3435,33 @@ <h3><dfn>Writing content</dfn></h3>
34433435
Let |options| be first argument.
34443436
</li>
34453437
<li>
3446-
[= list/For each =] |key| → |value| of |options|:
3447-
<ol>
3448-
<li>
3449-
If |key| equals "`signal`" and |value| is not `undefined`, set
3450-
|reader|.<a>[[\ScanAbortSignal]]</a> to |value|.
3451-
</li>
3452-
</ol>
3438+
Let |signal:AbortSignal| be the |options|’ dictionary member
3439+
of the same name if present, or `null` otherwise.
3440+
</li>
3441+
<li>
3442+
If |signal|’s [= AbortSignal/aborted flag =] is set, then reject |p|
3443+
with an {{"AbortError"}} {{DOMException}} and return |p|.
34533444
</li>
34543445
<li>
3455-
If |reader|.<a>[[\ScanAbortSignal]]</a>'s [= AbortSignal/aborted flag =] is
3456-
set, then reject |p| with a {{"AbortError"}} {{DOMException}}
3457-
and return |p|.
3446+
If |signal| is not `null`, then
3447+
<a data-cite="dom#abortsignal-abort-algorithms">
3448+
add the following abort steps</a> to |signal|:
3449+
<ol>
3450+
<li>
3451+
Clear the <a>pending read tuple</a> .
3452+
</li>
3453+
<li>
3454+
Make a request to stop listening to <a>NDEF message</a>s
3455+
on all <a>NFC adapter</a>s.
3456+
</li>
3457+
</ol>
34583458
</li>
34593459
<li>
3460-
If |reader|.<a>[[\ScanAbortSignal]]</a> is not `null`, then
3461-
<a data-cite="dom#abortsignal-abort-algorithms">add the following
3462-
abort steps</a> to |reader|.<a>[[\ScanAbortSignal]]</a>:
3460+
[=promise/React=] to |p|:
34633461
<ol>
34643462
<li>
3465-
Clear the <a>pending read tuple</a>.
3466-
</li>
3467-
<li>
3468-
Make a request to stop listening to <a>NDEF message</a>s
3469-
on all <a>NFC adapter</a>s.
3463+
If |p| was settled (fulfilled or rejected), then clear the
3464+
<a>pending read tuple</a>.
34703465
</li>
34713466
</ol>
34723467
</li>

0 commit comments

Comments
 (0)