[whatwg/dom] Specify that AbortController#abort() be bound to AbortController instance (#981)

The AbortController/Signal pattern is a bit cumbersome to use because it requires referencing the `signal` and `abort` and abort properties through the controller instance, which has no real utility other than as a container for these two properties. 

If `abort()` was bound to the contoller instance, developers could easily destructure the object rather than having to maintain an navigate through a 'controller' reference.

For example, take this use case where an abortable action is being peformed, while delegating the `abort` function to an external control...

```javascript
// Abort controller for this action ...
const abortController = new AbortController();

// Delegate the abort function to external control (e.g. clickable button)
$('#someButton').addEventListener('click', () => abortController.abort());

// abortable actions
await someAction(abortController.signal);
await otherAction(abortController.signal);

// etc...
```

Making the suggested change would allow for this code, instead...
```javascript
const {signal, abort} = new AbortController();

// ... abortable by some external event
$('#someButton').addEventListener('click', abort);

// ... now do actions, checking abort status
await someAction(signal);
await someAction(signal);
```

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/981

Received on Tuesday, 18 May 2021 14:07:11 UTC