W3C home > Mailing lists > Public > public-web-bluetooth-log@w3.org > October 2016

Re: [web-bluetooth] Improve the getAvailability() design

From: Jeffrey Yasskin via GitHub <sysbot+gh@w3.org>
Date: Fri, 07 Oct 2016 19:01:54 +0000
To: public-web-bluetooth-log@w3.org
Message-ID: <issue_comment.created-252334579-1475866912-sysbot+gh@w3.org>
```js
navigator.bluetooth.getAvailability().then(isAvailable => {
  bluetoothUI.hidden = !isAvailable;
});
navigator.bluetooth.addEventListener('availabilitychanged', e => {
  bluetoothUI.hidden = !e.value;
});
```

currently duplicates the .hidden logic. It's not straightforward to 
remove the duplication because the two functions take different kinds 
of arguments.

```js
navigator.bluetooth.watchAvailability(isAvailable => {
  bluetoothUI.hidden = !isAvailable;
});
```

would work, as would

```js
navigator.bluetooth.addEventListener('availabilitychanged', e => {
  bluetoothUI.hidden = !e.value;
});
navigator.bluetooth.watchAvailability();
```

if we said that `watchAvailability()` fires the event even if the 
availability hasn't changed, but doing the second would cause:

```js
navigator.bluetooth.addEventListener('availabilitychanged', e => 
console.log(e))
navigator.bluetooth.watchAvailability();
// Elsewhere:
navigator.bluetooth.addEventListener('availabilitychanged', e => 
console.log(e))
navigator.bluetooth.watchAvailability();
```

to log 3 times instead of 2.

-- 
GitHub Notification of comment by jyasskin
Please view or discuss this issue at 
https://github.com/WebBluetoothCG/web-bluetooth/issues/307#issuecomment-252334579
 using your GitHub account
Received on Friday, 7 October 2016 19:02:02 UTC

This archive was generated by hypermail 2.3.1 : Friday, 7 October 2016 19:02:02 UTC