Re: [whatwg/dom] Make it possible to observe connected-ness of a node (#533)

wessberg left a comment (whatwg/dom#533)

@dead-claudia yes, thanks for clarifying this to prevent potential misunderstandings. I'm fully aligned with that, and I think there is strength in that it follows the same design principles as existing observers such as `MutationObserver`, `ResizeObserver`, and `IntersectionObserver`. 

E.g. something like this would be ideal to me:

```javascript
const observer = new ConnectionObserver(entries => {
 for (const {connected, target} of entries) {
  console.log("target:", target);
  console.log("connected:", connected);
 }
});

// Observe 'someElement' for connectedness (synchronous)
observer.observe(someElement);

// Eventually disconnect the observer (synchronous)
observer.disconnect();
```

I made a little proof of concept of that [here](https://github.com/wessberg/connection-observer), which works well, but requires patching `Element.prototype.attachShadow`, which is unfortunate.

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

Message ID: <whatwg/dom/issues/533/2834228833@github.com>

Received on Monday, 28 April 2025 07:27:04 UTC