Description
This would fix #77 along with all the other benefits that keyed iteration would bring.
What we definitely would need is a way to move fragments around in the DOM.
To achieve this, I would split the render
(constructor) method into separate create
and mount/insert
methods.
create
would do createElement etc.mount
(orinsert
, pending bikeshed) would actually mount the elements to the DOM. Instead of making a distinction foruseAnchor
, I would just always generate code such asparent.insertBefore( elem, anchor )
, sinceinsertBefore
is the same asappendChild
whenanchor
is undefined.
[this would also go in the direction I was thinking of in #37]
As for the #each
itself, it would be as simple as iterating the list and create
fragments that do not exist yet, then mount
the fragment to the anchor, effectively moving already existing fragments. And then just unmount/teardown all the leftovers.
That should do as a first naive solution. Not moving existing fragments at all would require a more elaborate list diff, using lcs (longest common subsequence) and friends.
Any ideas on that @Rich-Harris?