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

@othermaciej I think most of your questions have been answered by now, but I'll try and summarize my responses quickly.

**What is the benefit of adapting Observables to Promises?**

The primary benefit of adapting Observables into Promises is that makes it possible to await events inside of async functions. Consider the following example which collects a signature on a canvas:

```js
async function getSignature(signatureCanvas, abortSignal) {
  await.cancelToken = cancelToken;
  const toPoint = e => ({ x: e.offsetX, y: e.offsetY });
  const sigMouseDowns = signatureCanvas.on('mousedown').map(toPoint);
  const sigMouseMoves = signatureCanvas.on('mousemove').map(toPoint);
  const sigMouseUps   = signatureCanvas.on('mouseup').map(toPoint);
  
  while(true) {
    let lastPointClicked = await sigMouseDowns.first(abortSignal);

    await sigMouseMoves.takeUntil(sigMouseUps).
      forEach(
        point => {
        strokeLine(signatureCanvas, lastPointClicked.x, lastPointClicked.y, point.x, point.y);
          lastPointClicked = point;
        },
        abortSignal);
  }
}
```
**Does the map/filter stuff really provide meaningful syntactic sugar?**

Its worth noting the same question could be asked of Array’s `map` and `filter` methods. The value of map/filter is not necessarily that using these methods is always terser, but rather that they enable composition. This means that one module can filter an Observable, and another that accepts that filtered Observable and map over it, and so on. 

-- 
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-351734336

Received on Thursday, 14 December 2017 14:58:16 UTC