- From: Rasmus Schultz <notifications@github.com>
- Date: Sun, 04 Apr 2021 07:13:35 -0700
- To: whatwg/dom <dom@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/dom/issues/891/813040331@github.com>
I'm particularly interested in `parentNode.reorderChildren`, which could probably greatly simplify the reconciliation algorithms in some UI libraries, where reordering (in as few operations as possible) is often the only really "tricky" part. Reconciliation generally adds a lot of complexity - there are many different implementations with many pros and cons, and the code tends to be fairly difficult to understand. Some concerns/reservations about this feature though: 1. Adding this feature would most likely be a breaking change in terms of `MutationObserver`, which would likely require a new type of mutation? Existing code that currently captures *all* mutations would essentially be incompatible with any newer code that uses the feature - and so, most likely, must be regarded as a breaking change? 2. It probably can't be polyfilled? If you implement a polyfill that uses existing DOM mutations to affect the same change, `MutationObserver` would broadcast these as individual changes. 3. What happens if you pass nodes that aren't already child-nodes of the given parent? Throwing errors of course is one option. Alternatively, this could work like `appendChild` and remove the node from somewhere else, if already present in the document. 4. What happens if you *omit* an existing child-node from the list? Again, throwing errors is an option. More likely, what someone meant to do though, was remove the missing nodes. (3) and (4) makes me think a method like `setChildren` might be more meaningful - this would clear out nodes no longer in the given list of node, add or move nodes already present in the document, essentially forcing the list of children into a particular state, in a single operation, which is what most UI libraries are trying to do. This seems more consistent with e.g. `appendChild` and is probably more generally useful? For example, this would make it easy (and fast) to implement sortable table rows. -- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/whatwg/dom/issues/891#issuecomment-813040331
Received on Sunday, 4 April 2021 14:13:48 UTC