Re: [whatwg/dom] Improving ergonomics of events with Observable (#544)

@othermaciej 

> Does the Promise return of first() mean that event dispatch to a client that registered with first() takes an extra trip around the event loop?

Think of it like:

```js
function first(el, type) {
  return new Promise(resolve => {
    el.addEventListener(type, resolve, { once: true });
  });
}

first(link, 'click').then(event => {
  // …
});
```

Since microtasks are processed per event callback (if the stack is empty), it's all within the same turn of the event loop. This also happens before unsetting the event's passive listener flag, so preventing default should be fine for spec-dispatched events (cc @annevk).

Events dispatched via JS won't be cancellable from `.first` and other promise-returning methods, as the microtask checkpoint is skipped because the stack isn't empty. This could become a bit of a gotcha.

> Does the map/filter stuff really provide meaningful syntactic sugar? For example, take this case:

I think the main benefit is in providing an observer that's pre-filtered to another piece of code. I agree that there isn't much benefit in the one-liner.

-- 
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/544#issuecomment-351722701

Received on Thursday, 14 December 2017 14:17:22 UTC