- From: Andrea Giammarchi <notifications@github.com>
- Date: Wed, 14 Feb 2024 13:07:20 -0800
- To: whatwg/dom <dom@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/dom/issues/1255/1944590622@github.com>
First of all, **thank you**! I've been vocal about this issue about forever and part of one of the biggest discussions you've linked. As author of various "*reactive*" libraries and somehow veteran of the "*DOM diffing field*", I'd like to add an idea: > The API shape for this new primitive is an open question. Below are a few ideas: I understand a node can be moved from `<main>` to an `<aside>` element and this proposal should still work but I think we should **not** discard the **Range API**: * most modern libraries have a concept of *fragments*, inevitably represented as virtual because there's no persistent fragment whatsoever yet on the DOM (I've been vocal about this too) * in a classic table sort mechanism there could be only few *TRs* moved within a specific place and taht's the same for *LIs* and others ... if any proposed API consider only *parentNode* to work that would **not** satisfy most fragment based requirements where areas are confined within Virtual DOM or comment nodes to confine those special cases while the *Range* api could instead simply select a node start, a node end, and update atomically inner nodes On top of this I hope whatever solution comes to mind works well with *DOM diffing*, so that new nodes can even pass through the usual DOM dance when the parent is changed or they become live, removed nodes that won't land anywhere else would eventually invoke `disconnectedCallback` if Custom Elements, but nodes already present in that container and moved around basically do nothing in terms of state, they are just shuffled in the layout, if they do. As quick idea to eventually signal a node is going to be moved in an atomic way, and assuming it's targeting also a live parent, I think something like `parent.insertBeforeAtomic(node[, reference])` could be an interesting approach to consider as that basically solves everything, from `append` to `prepend` to any other case `insertBefore` works wonderfully well and it hints that such node should: * do nothing if the parent is the same as before ... just move it and skip all the things * trigger `connectedCallback` if the node was not live * ... that's it? As `insertBefore` covers `append`, `appendChild`, `append` and `prepend` with ease, it imght be the easiest starting point to have something working and useful for the variety of virtual fragments based solutions and diffing APIs out there. I hope this answer of mine makes sense and maybe trigger some even better idea / API. -- Reply to this email directly or view it on GitHub: https://github.com/whatwg/dom/issues/1255#issuecomment-1944590622 You are receiving this because you are subscribed to this thread. Message ID: <whatwg/dom/issues/1255/1944590622@github.com>
Received on Wednesday, 14 February 2024 21:07:27 UTC