Re: [w3ctag/design-reviews] User Idle Detection (#336)

Ha, I love `IdleDetector` @kenchris  and thanks for pointing out the sensors API for precedence/inspiration @domenic !

Looking at the [Accelerometer](https://w3c.github.io/sensors/#feature-detection) for inspiration, here is what it looks like:

```
let accelerometer = new Accelerometer({ frequency: 10 });
accelerometer.addEventListener('error', event => {
    // Handle runtime errors.
});
accelerometer.addEventListener('reading', () => reloadOnShake(accelerometer));
accelerometer.start();
```

@kenchris curious: is there a specific reason why you chose a `onreading` callback `EventHandler` as opposed to using the `addEventListener()` method of the subclassing of `EventTarget`? For example, would something along these lines be more consistent with the `Accelerometer` design:

```
let idleDetector = new IdleDetector({ threshold: 60 });
idleDetector.addEventListener('reading', () => reloadOnShake(idleDetector));
idleDetector.start();
```

WDYT?

Putting aside this, I also really like the design for one-shot queries with a static async method. This works really well to me:

```
const reading = await IdleDetector.read({ threshold: 2 * 60 });
```

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3ctag/design-reviews/issues/336#issuecomment-470722359

Received on Thursday, 7 March 2019 22:26:42 UTC