Re: [whatwg/dom] Disconnect single target instead of all (#126)

I've been using this as a work around:

```typescript
class MutationObserverUnobservable extends MutationObserver {
  private observerTargets: Array<{
    target: Node;
    options?: MutationObserverInit;
  }> = [];

  observe(target: Node, options?: MutationObserverInit): void {
    this.observerTargets.push({ target, options });

    return super.observe(target, options);
  }

  unobserve(target: Node): void {
    const newObserverTargets = this.observerTargets.filter(
      (ot) => ot.target !== target
    );
    this.observerTargets = [];
    this.disconnect();
    newObserverTargets.forEach((ot) => {
      this.observe(ot.target, ot.options);
    });
  }
}
```

I was pretty surprised the *Observer apis didn't all follow a similar interface. It would be nice to see unobserve in the spec :)

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

Message ID: <whatwg/dom/issues/126/1049814948@github.com>

Received on Thursday, 24 February 2022 12:34:42 UTC