- From: Andrea Giammarchi <notifications@github.com>
- Date: Wed, 16 Apr 2025 10:15:56 -0700
- To: whatwg/dom <dom@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/dom/issues/736/2810214830@github.com>
WebReflection left a comment (whatwg/dom#736) On a second thought, maybe my current implementation is misleading so please let's start from scratch with the architecture behind, so that any `parent.children[0].parentNode != parent` concern can happily fade away? A *NodeGroup* (or GroupNode) is a facade that happens to implement all `Node` and `Element` accessors and methods. It is related to 3 things: 2 boundaries and a fragment. Boundaries are there to help the facade work accordingly while the fragment helps storing content until such facade gets appended. ```js const group = { start: document.createComment('<>'), end: document.createComment('</>'), fragment: document.createDocumentFragment(), ...allDOMMethodsAndAccessors, get children() { if (this.start.parentNode) { const children = []; let { start, end } = this; while ((start = start.nextSibling)) { if (start === end) break; children.push(start); } return children; // as ChildNodes } else return this.fragment.children; } }; ``` That `children` in there is a *facade* of an accessor: * when the boundaries have a parent node, condition that happens when that `group` get appended somewhere, `children` returns nodes in between boundaries * when the boundaries don't have a parent node, condition that happens when the `group` gets removed, these are within the `fragment` and returned as such * boundaries are never within the fragment, these are completely detached from the `group` content In this scenario, you need to hold that `group` reference, you know it's an instance of *NodeGroup* and you **never expect** `group.children[0].parentNode == group` because **that would never be the case**. So, because anyone can call a property `children`, assuming my implementation was like that, and *GorupNode* is not even an instance of `Node` itself, would all these concerns disappear about everything as it would be clear that *GroupNode* is just a special range of nodes orchestrator that needs to be understood by all Nodes mutation APIs, reason I've chosen the easy way extending a *DocumentFragment* ? Would making *GorupNode* **not a node** fix all the concerns around this topic? Thanks. -- Reply to this email directly or view it on GitHub: https://github.com/whatwg/dom/issues/736#issuecomment-2810214830 You are receiving this because you are subscribed to this thread. Message ID: <whatwg/dom/issues/736/2810214830@github.com>
Received on Wednesday, 16 April 2025 17:16:00 UTC