Skip to content

Commit

Permalink
Use counter instead of Set of observed nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
westonruter committed Jan 7, 2025
1 parent 88d679c commit abd3747
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/interactivity/src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const initialVdom = new WeakMap< Element, ComponentChild[] >();

// Initialize the router with the initial DOM.
export const init = async () => {
const pendingNodes = new Set();
let observedNodeCount = 0;

const intersectionObserver = new window.IntersectionObserver(
async ( entries ) => {
Expand All @@ -40,8 +40,8 @@ export const init = async () => {

const node = entry.target;
intersectionObserver.unobserve( node );
pendingNodes.delete( node );
if ( pendingNodes.size === 0 ) {
observedNodeCount--;
if ( observedNodeCount === 0 ) {
intersectionObserver.disconnect();
}

Expand Down Expand Up @@ -76,8 +76,8 @@ export const init = async () => {
setTimeout( resolve, 0 );
} );

observedNodeCount = nodes.length;
for ( const node of nodes ) {
pendingNodes.add( node );
intersectionObserver.observe( node );
}
};

0 comments on commit abd3747

Please sign in to comment.