1
1
import { expect , it } from "vitest" ;
2
2
import { Equal , Expect } from "../helpers/type-utils" ;
3
3
4
- interface InfiniteScrollParams < TRow > {
4
+ type MakeInfiniteScrollParams < TRow > = {
5
5
key : keyof TRow ;
6
- fetchRows : ( ) => Promise < TRow [ ] > ;
7
6
initialRows ?: TRow [ ] ;
8
- }
7
+ fetchRows : ( ) => Promise < TRow [ ] > | TRow [ ] ;
8
+ } ;
9
9
10
- const makeInfiniteScroll = < TRow > ( params : InfiniteScrollParams < TRow > ) => {
11
- const data : TRow [ ] = params . initialRows || [ ] ;
10
+ const makeInfiniteScroll = < TRow > ( params : MakeInfiniteScrollParams < TRow > ) => {
11
+ const data = params . initialRows || [ ] ;
12
12
13
13
const scroll = async ( ) => {
14
14
const rows = await params . fetchRows ( ) ;
@@ -24,7 +24,7 @@ const makeInfiniteScroll = <TRow>(params: InfiniteScrollParams<TRow>) => {
24
24
it ( "Should fetch more data when scrolling" , async ( ) => {
25
25
const table = makeInfiniteScroll ( {
26
26
key : "id" ,
27
- fetchRows : ( ) => Promise . resolve ( [ { id : 1 , name : "John" } ] ) ,
27
+ fetchRows : async ( ) => [ { id : 1 , name : "John" } ] ,
28
28
} ) ;
29
29
30
30
await table . scroll ( ) ;
@@ -72,6 +72,6 @@ it("Should allow you to pass initialRows", () => {
72
72
] ) ;
73
73
74
74
type tests = [
75
- Expect < Equal < typeof rows , Array < { id : number ; name : string } > > > ,
75
+ Expect < Equal < typeof rows , Array < { id : number ; name : string } > > >
76
76
] ;
77
77
} ) ;
0 commit comments