Skip to content

Commit

Permalink
fix: too many onVisibleRangeUpdate event for a given position
Browse files Browse the repository at this point in the history
  • Loading branch information
orefalo committed Oct 21, 2024
1 parent d963650 commit 080143c
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/lib/VirtualListNew.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
avgSizeInPx?: number;
clientHeight?: number;
clientWidth?: number;
startIdx?: number;
endIdx?: number;
}
// ====== PROPERTIES ================
Expand Down Expand Up @@ -260,17 +262,16 @@
$effect(() => {
//@ts-expect-error unused no side effect
scrollToIndex, scrollToAlignment, scrollToOffset, items.length, sizingCalculator;
scrollToIndex,
scrollToAlignment,
scrollToOffset,
items.length,
sizingCalculator,
startIdx,
endIdx;
propsUpdated();
});
$effect(() => {
if (onVisibleRangeUpdate) {
const vr = getVisibleRange(isHorizontal ? clientWidth : clientHeight, curState.offset);
onVisibleRangeUpdate(vr);
}
});
$effect(() => {
const { offset, scrollChangeReason } = curState;
Expand Down Expand Up @@ -324,6 +325,13 @@
};
}
if (onVisibleRangeUpdate) {
if (prevProps?.startIdx !== startIdx || prevProps?.endIdx !== endIdx) {
const vr = getVisibleRange(isHorizontal ? clientWidth : clientHeight, curState.offset);
onVisibleRangeUpdate(vr);
}
}
prevProps = {
scrollToIndex,
scrollToAlignment,
Expand All @@ -332,7 +340,9 @@
sizingCalculator,
avgSizeInPx,
clientHeight,
clientWidth
clientWidth,
startIdx,
endIdx
};
}
Expand Down

0 comments on commit 080143c

Please sign in to comment.