clear-virtualizer 0.1.3 → 0.1.4

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/lib/index.cjs CHANGED
@@ -129,7 +129,18 @@ function useVirtualizer({ count, estimateSize, overscan = DEFAULT_OVERSCAN }) {
129
129
  if (fenwickRef.current === null || !fenwickRef.current.total())
130
130
  fenwickRef.current = getFenwickTree(count, estimateSize);
131
131
  if (prevCountRef.current !== count) {
132
- fenwickRef.current = getFenwickTree(count, estimateSize);
132
+ const prevTree = fenwickRef.current;
133
+ const prevCount = prevCountRef.current;
134
+ const nextTree = getFenwickTree(count, estimateSize);
135
+ if (prevTree && prevCount > 0) {
136
+ const keep = Math.min(prevCount, count);
137
+ for (let i = 0; i < keep; i++) {
138
+ const delta = prevTree.prefixSum(i + 1) - prevTree.prefixSum(i) - (nextTree.prefixSum(i + 1) - nextTree.prefixSum(i));
139
+ if (delta !== 0)
140
+ nextTree.update(i, delta);
141
+ }
142
+ }
143
+ fenwickRef.current = nextTree;
133
144
  prevCountRef.current = count;
134
145
  }
135
146
  const computeItems = react.useCallback(
package/lib/index.js CHANGED
@@ -127,7 +127,18 @@ function useVirtualizer({ count, estimateSize, overscan = DEFAULT_OVERSCAN }) {
127
127
  if (fenwickRef.current === null || !fenwickRef.current.total())
128
128
  fenwickRef.current = getFenwickTree(count, estimateSize);
129
129
  if (prevCountRef.current !== count) {
130
- fenwickRef.current = getFenwickTree(count, estimateSize);
130
+ const prevTree = fenwickRef.current;
131
+ const prevCount = prevCountRef.current;
132
+ const nextTree = getFenwickTree(count, estimateSize);
133
+ if (prevTree && prevCount > 0) {
134
+ const keep = Math.min(prevCount, count);
135
+ for (let i = 0; i < keep; i++) {
136
+ const delta = prevTree.prefixSum(i + 1) - prevTree.prefixSum(i) - (nextTree.prefixSum(i + 1) - nextTree.prefixSum(i));
137
+ if (delta !== 0)
138
+ nextTree.update(i, delta);
139
+ }
140
+ }
141
+ fenwickRef.current = nextTree;
131
142
  prevCountRef.current = count;
132
143
  }
133
144
  const computeItems = useCallback(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clear-virtualizer",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "A lightweight React hook for virtualized lists and tables with dynamic row heights, measured automatically",
5
5
  "type": "module",
6
6
  "main": "./lib/index.cjs",