Re: [whatwg/dom] Proposal: New method to reorder child nodes (#891)

We basically need a swap function that doesn't remove elements from DOM.

I'm not intimately familiar with DOM innerworkings but if DOM is seen as a Tree then it's not clear why swapping is so hard. In a tree structure, if I wanted to swap I'd assign one child to a temporary variable and then temp to node being swapped. 

```
t= children[1]
children[1] = children[2]
children[2] = t
```
But maybe overwriting children[1] causes element to be taken out of DOM and wiped clean, DOM is recalculated/rerendered, even though it's added back in next step at children[2]'s position. So I see two solutions:

1) Either have hidden carry over child, that is never visible, so when swapping 1st element being swapped can be assigned to it and therefore remains part of the DOM preventing garbage it getting cut of from DOM tree and wiped clean.

2) Or have batch render/compute. Don't trigger render on element being removed, allow internal swap function to do step 1,2,3 and then recompute/rendering logic.. Preventing children[1] content from being wiped right when it's over written as it's still referred by DOM.

Thoughts?

-- 
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-914004606

Received on Tuesday, 7 September 2021 05:38:10 UTC