v0.2.90
This commit is contained in:
1 parent
0abc8e871d
commit
4da41a1404
10 files changed
+458
-49
No files matched your search
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright (C) 2026 Mateusz Gruszczynski @linuxiarz.pl
|
||||
* Source-Available Code / Dual-Licensed.
|
||||
* See LICENSE.md for terms.
|
||||
*/
|
||||
|
||||
// Preserve existing nodes. Remove stale entries first: otherwise deleting a
|
||||
// user near the start of a 1000-person list would move every following node.
|
||||
// `desired` must contain each node at most once.
|
||||
export function reconcileChildren(container, desired) {
|
||||
const retained = new Set(desired);
|
||||
for (const node of [...container.childNodes]) {
|
||||
if (!retained.has(node)) node.remove();
|
||||
}
|
||||
let cursor = container.firstChild;
|
||||
for (const node of desired) {
|
||||
if (node === cursor) cursor = cursor.nextSibling;
|
||||
else container.insertBefore(node, cursor);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user