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

@othermaciej Thanks for the link to `AbortController`.  Here are [the docs for `takeUntil`](http://reactivex.io/rxjs/class/es6/Observable.js~Observable.html#instance-method-takeUntil).

In short, it aborts the subscription when its argument emits a value.  Something like this:

```typescript

Observable.prototype.takeUntil = function (cancellation$) {
  return new Observable(
    (observer) => {
      const upstreamSubscription = this.subscribe(observer);
      const cancellationSubscription = cancellation$.subscribe(
        () => {
          upstreamSubscription.abort();
          cancellationSubscription.abort();
        }
      );
    }
  }
}

element.on('mousemove').takeUntil('mouseup').subscribe(console.log)
```
would log all the `mousemove`s until the next emission from `mouseup`.  Then, both the subscription to `mousemove` and to `mouseup` would be aborted.

@benlesh has [written more about this approach](https://medium.com/@benlesh/rxjs-dont-unsubscribe-6753ed4fda87).  Note: in that article, `abort` is called `unsubscribe`. 

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

Received on Thursday, 14 December 2017 05:13:26 UTC