Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
inokawa committed Jul 28, 2023
1 parent 460e7a1 commit 11023a6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/core/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export const createVirtualStore = (
const shouldAutoEstimateItemSize = !itemSize;
const initialItemSize = itemSize || 40;
const cache =
(cacheSnapshot as unknown as Cache | undefined) ??
(cacheSnapshot as unknown as Cache | undefined) ||
initCache(elementsCount, initialItemSize);
let viewportSize = initialItemSize * max(initialItemCount - 1, 0);
let scrollOffset = 0;
Expand Down
20 changes: 10 additions & 10 deletions src/react/VGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -358,14 +358,14 @@ export const VGrid = forwardRef<VGridHandle, VGridProps>(
};
}, [children]);

const startRowIndexWithMargin = max(startRowIndex - overscan, 0);
const endRowIndexWithMargin = min(endRowIndex + overscan, rowCount - 1);
const startColIndexWithMargin = max(startColIndex - overscan, 0);
const endColIndexWithMargin = min(endColIndex + overscan, colCount - 1);
const overscanedStartRowIndex = max(startRowIndex - overscan, 0);
const overscanedEndRowIndex = min(endRowIndex + overscan, rowCount - 1);
const overscanedStartColIndex = max(startColIndex - overscan, 0);
const overscanedEndColIndex = min(endColIndex + overscan, colCount - 1);
const items = useMemo(() => {
const res: ReactElement[] = [];
for (let i = startRowIndexWithMargin; i <= endRowIndexWithMargin; i++) {
for (let j = startColIndexWithMargin; j <= endColIndexWithMargin; j++) {
for (let i = overscanedStartRowIndex; i <= overscanedEndRowIndex; i++) {
for (let j = overscanedStartColIndex; j <= overscanedEndColIndex; j++) {
res.push(
<Cell
key={genKey(i, j)}
Expand All @@ -385,10 +385,10 @@ export const VGrid = forwardRef<VGridHandle, VGridProps>(
return res;
}, [

Check warning on line 386 in src/react/VGrid.tsx

View workflow job for this annotation

GitHub Actions / check

React Hook useMemo has missing dependencies: 'hStore', 'isRtl', 'itemElement', 'resizer', and 'vStore'. Either include them or remove the dependency array
render,
startRowIndexWithMargin,
endRowIndexWithMargin,
startColIndexWithMargin,
endColIndexWithMargin,
overscanedStartRowIndex,
overscanedEndRowIndex,
overscanedStartColIndex,
overscanedEndColIndex,
]);

return (
Expand Down
8 changes: 4 additions & 4 deletions src/react/VList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,11 @@ export const VList = forwardRef<VListHandle, VListProps>(
[]

Check warning on line 264 in src/react/VList.tsx

View workflow job for this annotation

GitHub Actions / check

React Hook useImperativeHandle has missing dependencies: 'scroller' and 'store'. Either include them or remove the dependency array
);

const startIndexWithMargin = max(startIndex - overscan, 0);
const endIndexWithMargin = min(endIndex + overscan, count - 1);
const overscanedStartIndex = max(startIndex - overscan, 0);
const overscanedEndIndex = min(endIndex + overscan, count - 1);
const items = useMemo(() => {
const res: ReactElement[] = [];
for (let i = startIndexWithMargin; i <= endIndexWithMargin; i++) {
for (let i = overscanedStartIndex; i <= overscanedEndIndex; i++) {
const e = elements[i];
// This can be undefined when items are removed
if (exists(e)) {
Expand All @@ -287,7 +287,7 @@ export const VList = forwardRef<VListHandle, VListProps>(
}
}
return res;
}, [elements, startIndexWithMargin, endIndexWithMargin]);
}, [elements, overscanedStartIndex, overscanedEndIndex]);

Check warning on line 290 in src/react/VList.tsx

View workflow job for this annotation

GitHub Actions / check

React Hook useMemo has missing dependencies: 'isHorizontal', 'isRtl', 'itemElement', 'resizer', and 'store'. Either include them or remove the dependency array

return (
<Window
Expand Down
8 changes: 4 additions & 4 deletions src/react/WVList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,11 @@ export const WVList = forwardRef<WVListHandle, WVListProps>(
[]
);

const startIndexWithMargin = max(startIndex - overscan, 0);
const endIndexWithMargin = min(endIndex + overscan, count - 1);
const overscanedStartIndex = max(startIndex - overscan, 0);
const overscanedEndIndex = min(endIndex + overscan, count - 1);
const items = useMemo(() => {
const res: ReactElement[] = [];
for (let i = startIndexWithMargin; i <= endIndexWithMargin; i++) {
for (let i = overscanedStartIndex; i <= overscanedEndIndex; i++) {
const e = elements[i];
// This can be undefined when items are removed
if (exists(e)) {
Expand All @@ -223,7 +223,7 @@ export const WVList = forwardRef<WVListHandle, WVListProps>(
}
}
return res;
}, [elements, startIndexWithMargin, endIndexWithMargin]);
}, [elements, overscanedStartIndex, overscanedEndIndex]);

return (
<Window
Expand Down

0 comments on commit 11023a6

Please sign in to comment.