cogsbox-state 0.5.423 → 0.5.424
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/CogsState.jsx +474 -467
- package/dist/CogsState.jsx.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +22 -6
package/package.json
CHANGED
package/src/CogsState.tsx
CHANGED
|
@@ -1824,7 +1824,7 @@ function createProxyHandler<T>(
|
|
|
1824
1824
|
const wasAtBottomRef = useRef(true);
|
|
1825
1825
|
const userHasScrolledAwayRef = useRef(false);
|
|
1826
1826
|
const previousCountRef = useRef(0);
|
|
1827
|
-
|
|
1827
|
+
const lastRangeRef = useRef(range);
|
|
1828
1828
|
// Subscribe to shadow state updates
|
|
1829
1829
|
useEffect(() => {
|
|
1830
1830
|
const unsubscribe = getGlobalStore
|
|
@@ -1956,7 +1956,7 @@ function createProxyHandler<T>(
|
|
|
1956
1956
|
userHasScrolledAwayRef.current = true;
|
|
1957
1957
|
}
|
|
1958
1958
|
|
|
1959
|
-
// If user scrolls back to bottom,
|
|
1959
|
+
// If user scrolls back to bottom, cle
|
|
1960
1960
|
if (distanceFromBottom < 5) {
|
|
1961
1961
|
userHasScrolledAwayRef.current = false;
|
|
1962
1962
|
}
|
|
@@ -1979,10 +1979,26 @@ function createProxyHandler<T>(
|
|
|
1979
1979
|
endIndex = i;
|
|
1980
1980
|
}
|
|
1981
1981
|
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1982
|
+
const newStartIndex = Math.max(0, startIndex);
|
|
1983
|
+
const newEndIndex = Math.min(
|
|
1984
|
+
totalCount,
|
|
1985
|
+
endIndex + 1 + overscan
|
|
1986
|
+
);
|
|
1987
|
+
|
|
1988
|
+
// THE FIX: Only update state if the visible range of items has changed.
|
|
1989
|
+
if (
|
|
1990
|
+
newStartIndex !== lastRangeRef.current.startIndex ||
|
|
1991
|
+
newEndIndex !== lastRangeRef.current.endIndex
|
|
1992
|
+
) {
|
|
1993
|
+
lastRangeRef.current = {
|
|
1994
|
+
startIndex: newStartIndex,
|
|
1995
|
+
endIndex: newEndIndex,
|
|
1996
|
+
};
|
|
1997
|
+
setRange({
|
|
1998
|
+
startIndex: newStartIndex,
|
|
1999
|
+
endIndex: newEndIndex,
|
|
2000
|
+
});
|
|
2001
|
+
}
|
|
1986
2002
|
};
|
|
1987
2003
|
|
|
1988
2004
|
container.addEventListener("scroll", handleScroll, {
|