Skip to content

Commit d9df4a4

Browse files
authored
Merge pull request #41 from zaewc/develop
develop to master
2 parents d3ca64b + 02235bf commit d9df4a4

35 files changed

+2266
-263
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "scrolloop",
3-
"version": "0.4.0",
3+
"version": "0.5.0",
44
"repository": {
55
"type": "git",
66
"url": "git+https://github.com/976520/scrolloop.git"

packages/core/src/virtualizer/Virtualizer.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ export class Virtualizer {
1111
#count: number;
1212
readonly #overscan: number;
1313
#plugins: Plugin[];
14-
readonly #onChange?: (state: VirtualizerState) => void;
14+
readonly #onChange: ((state: VirtualizerState) => void) | undefined;
1515

1616
readonly #layoutStrategy: LayoutStrategy;
1717
readonly #scrollSource: ScrollSource;
1818

1919
#state: VirtualizerState;
20-
readonly #unsubscribe?: () => void;
20+
readonly #unsubscribe: (() => void) | undefined;
2121

22-
#prevRenderRange?: { startIndex: number; endIndex: number };
23-
#prevVirtualItems?: VirtualItem[];
22+
#prevRenderRange: { startIndex: number; endIndex: number } | undefined;
23+
#prevVirtualItems: VirtualItem[] | undefined;
2424

2525
constructor(
2626
layoutStrategy: LayoutStrategy,

packages/core/tsconfig.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
"outDir": "./dist",
55
"declaration": true,
66
"declarationMap": true,
7-
"types": ["vitest/globals"]
7+
"types": ["vitest/globals"],
8+
"noUncheckedIndexedAccess": true,
9+
"exactOptionalPropertyTypes": true,
10+
"noImplicitOverride": true
811
},
912
"include": ["src/**/*", "tsup.config.ts"],
1013
"exclude": ["node_modules", "dist", "**/*.test.ts"]

packages/react-native/src/components/InfiniteList.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,20 @@ function InfiniteListInner<T>(props: InfiniteListProps<T>) {
5757
]);
5858

5959
const handleRangeChange = (range: Range) => {
60-
const prefetchStart = Math.max(
61-
0,
62-
Math.floor(range.startIndex / pageSize) -
63-
Math.floor(range.endIndex / pageSize)
64-
);
60+
const prefetchStart = Math.floor(range.startIndex / pageSize);
6561
const prefetchEnd =
6662
Math.floor(range.endIndex / pageSize) +
6763
prefetchThreshold +
6864
Math.ceil(overscan / pageSize);
6965

70-
findMissingPages(prefetchStart, prefetchEnd, pages, loadingPages);
66+
const missingPages = findMissingPages(
67+
prefetchStart,
68+
prefetchEnd,
69+
pages,
70+
loadingPages
71+
);
7172

72-
for (let page = prefetchStart; page <= prefetchEnd; page++) {
73+
for (const page of missingPages) {
7374
loadPage(page);
7475
}
7576
};

packages/react/src/components/InfiniteList.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,16 +130,13 @@ function InfiniteListInner<T>(props: InfiniteListProps<T>) {
130130
scrollTopRef.current = containerRef.current?.scrollTop ?? 0;
131131
return;
132132
}
133-
const ps = Math.max(
134-
0,
135-
((range.startIndex / pageSize) | 0) - ((range.endIndex / pageSize) | 0)
136-
);
133+
const ps = (range.startIndex / pageSize) | 0;
137134
const pe =
138135
((range.endIndex / pageSize) | 0) +
139136
prefetchThreshold +
140137
Math.ceil(overscan / pageSize);
141-
findMissingPages(ps, pe, mergedPages, loadingPages);
142-
for (let p = ps; p <= pe; p++) loadPage(p);
138+
const missingPages = findMissingPages(ps, pe, mergedPages, loadingPages);
139+
for (const p of missingPages) loadPage(p);
143140
},
144141
[
145142
isServerSide,

packages/react/src/hooks/useInfinitePages.ts

Lines changed: 0 additions & 103 deletions
This file was deleted.

packages/react/src/utils/canLoadPage.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

packages/react/src/utils/findMissingPages.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

packages/shared/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
"react": ">=18.0.0"
3535
},
3636
"devDependencies": {
37+
"@testing-library/jest-dom": "^6.9.1",
38+
"@testing-library/react": "^14.3.1",
39+
"jsdom": "^24.1.3",
3740
"react": "^18.2.0",
3841
"tsup": "^8.0.0",
3942
"typescript": "^5.0.0",

0 commit comments

Comments
 (0)