Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
inokawa committed Aug 2, 2023
1 parent 4c3b95e commit f2c64c2
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 23 deletions.
14 changes: 5 additions & 9 deletions src/core/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,13 @@ export type VirtualStore = {

export const createVirtualStore = (
elementsCount: number,
itemSize: number | undefined,
itemSize: number = 40,
initialItemCount: number = 0,
isReverse: boolean,
cacheSnapshot?: CacheSnapshot
cache: Cache = initCache(elementsCount, itemSize),
isReverse?: boolean,
shouldAutoEstimateItemSize?: boolean
): VirtualStore => {
const shouldAutoEstimateItemSize = !itemSize;
const initialItemSize = itemSize || 40;
const cache =
(cacheSnapshot as unknown as Cache | undefined) ||
initCache(elementsCount, initialItemSize);
let viewportSize = initialItemSize * max(initialItemCount - 1, 0);
let viewportSize = itemSize * max(initialItemCount - 1, 0);
let scrollOffset = 0;
let jumpCount = 0;
let jump: ScrollJump = 0;
Expand Down
14 changes: 2 additions & 12 deletions src/react/VGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -273,18 +273,8 @@ export const VGrid = forwardRef<VGridHandle, VGridProps>(
const [vStore, hStore, resizer, vScroller, hScroller, isRtl] = useStatic(
() => {
const _isRtl = !!rtlProp;
const _vs = createVirtualStore(
rowCount,
cellHeight,
initialRowCount,
false
);
const _hs = createVirtualStore(
colCount,
cellWidth,
initialColCount,
false
);
const _vs = createVirtualStore(rowCount, cellHeight, initialRowCount);
const _hs = createVirtualStore(colCount, cellWidth, initialColCount);
return [
_vs,
_hs,
Expand Down
4 changes: 3 additions & 1 deletion src/react/VList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
} from "./Viewport";
import { CustomItemComponent, ListItem } from "./ListItem";
import { CacheSnapshot } from "../core/types";
import { Cache } from "../core/cache";

export type ScrollMode = "reverse" | "rtl";

Expand Down Expand Up @@ -193,8 +194,9 @@ export const VList = forwardRef<VListHandle, VListProps>(
count,
initialItemSize,
initialItemCount,
cache as unknown as Cache | undefined,
mode === "reverse",
cache
!initialItemSize
);
return [
_store,
Expand Down
4 changes: 3 additions & 1 deletion src/react/WVList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
Viewport as DefaultViewport,
} from "./Viewport";
import { CustomItemComponent, ListItem } from "./ListItem";
import { Cache } from "../core/cache";

type CustomItemComponentOrElement =
| keyof JSX.IntrinsicElements
Expand Down Expand Up @@ -147,8 +148,9 @@ export const WVList = forwardRef<WVListHandle, WVListProps>(
count,
initialItemSize,
initialItemCount,
cache as unknown as Cache | undefined,
false,
cache
!initialItemSize
);

return [
Expand Down

0 comments on commit f2c64c2

Please sign in to comment.