- From: Sam Boylett <notifications@github.com>
- Date: Thu, 24 Feb 2022 04:34:29 -0800
- To: whatwg/dom <dom@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
Received on Thursday, 24 February 2022 12:34:42 UTC
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