Skip to content

Commit

Permalink
lower initialization cost
Browse files Browse the repository at this point in the history
Signed-off-by: Nyi Nyi Lwin <[email protected]>
  • Loading branch information
mdynnl committed Nov 15, 2024
1 parent d8f5ca6 commit 9161ac3
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions packages/dom-expressions/src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -569,14 +569,17 @@ function appendNodes(parent, array, marker = null) {
for (let i = 0, len = array.length; i < len; i++) parent.insertBefore(array[i], marker);
}

let moved;
const moved = new Set();
let scheduled = false;

function cleanChildren(parent, current, marker, replacement) {
if (!moved) {
moved = new WeakSet();
queueMicrotask(() => (moved = null));
if (!scheduled && moved.size) {
queueMicrotask(() => {
moved.clear();
scheduled = false;
})
scheduled = true;
}

if (marker === undefined) return (parent.textContent = "");
const node = replacement || document.createTextNode("");
if (current.length) {
Expand Down

0 comments on commit 9161ac3

Please sign in to comment.