1 | import { PureComponent, Validator, Requireable } from 'react';
|
2 | import { Index, IndexRange } from '../../index';
|
3 |
|
4 | export type InfiniteLoaderChildProps = {
|
5 | onRowsRendered: (params: IndexRange) => void;
|
6 | registerChild: (registeredChild: any) => void;
|
7 | };
|
8 |
|
9 | export type InfiniteLoaderProps = {
|
10 | /**
|
11 | * Function responsible for rendering a virtualized component.
|
12 | * This function should implement the following signature:
|
13 | * ({ onRowsRendered, registerChild }) => PropTypes.element
|
14 | *
|
15 | * The specified :onRowsRendered function should be passed through to the child's :onRowsRendered property.
|
16 | * The :registerChild callback should be set as the virtualized component's :ref.
|
17 | */
|
18 | children: (props: InfiniteLoaderChildProps) => React.ReactNode;
|
19 | /**
|
20 | * Function responsible for tracking the loaded state of each row.
|
21 | * It should implement the following signature: ({ index: number }): boolean
|
22 | */
|
23 | isRowLoaded: (params: Index) => boolean;
|
24 | /**
|
25 | * Callback to be invoked when more rows must be loaded.
|
26 | * It should implement the following signature: ({ startIndex, stopIndex }): Promise
|
27 | * The returned Promise should be resolved once row data has finished loading.
|
28 | * It will be used to determine when to refresh the list with the newly-loaded data.
|
29 | * This callback may be called multiple times in reaction to a single scroll event.
|
30 | */
|
31 | loadMoreRows: (params: IndexRange) => Promise<any>;
|
32 | /**
|
33 | * Minimum number of rows to be loaded at a time.
|
34 | * This property can be used to batch requests to reduce HTTP requests.
|
35 | */
|
36 | minimumBatchSize?: number | undefined;
|
37 | /**
|
38 | * Number of rows in list; can be arbitrary high number if actual number is unknown.
|
39 | */
|
40 | rowCount?: number | undefined;
|
41 | /**
|
42 | * Threshold at which to pre-fetch data.
|
43 | * A threshold X means that data will start loading when a user scrolls within X rows.
|
44 | * This value defaults to 15.
|
45 | */
|
46 | threshold?: number | undefined;
|
47 | /**
|
48 | * PLEASE NOTE
|
49 | * The [key: string]: any; line is here on purpose
|
50 | * This is due to the need of force re-render of PureComponent
|
51 | * Check the following link if you want to know more
|
52 | * https://github.com/bvaughn/react-virtualized#pass-thru-props
|
53 | */
|
54 | [key: string]: any;
|
55 | };
|
56 |
|
57 | /**
|
58 | * Higher-order component that manages lazy-loading for "infinite" data.
|
59 | * This component decorates a virtual component and just-in-time prefetches rows as a user scrolls.
|
60 | * It is intended as a convenience component; fork it if you'd like finer-grained control over data-loading.
|
61 | */
|
62 | export class InfiniteLoader extends PureComponent<InfiniteLoaderProps> {
|
63 | static propTypes: {
|
64 | children: Validator<(props: InfiniteLoaderChildProps) => React.ReactNode>;
|
65 | isRowLoaded: Validator<(params: Index) => boolean>;
|
66 | loadMoreRows: Validator<(params: IndexRange) => Promise<any>>;
|
67 | minimumBatchSize: Validator<number>;
|
68 | rowCount: Validator<number>;
|
69 | threshold: Validator<number>;
|
70 | };
|
71 |
|
72 | static defaultProps: {
|
73 | minimumBatchSize: 10;
|
74 | rowCount: 0;
|
75 | threshold: 15;
|
76 | };
|
77 |
|
78 | resetLoadMoreRowsCache(autoReload?: boolean): void;
|
79 | }
|
80 |
|
81 | export default InfiniteLoader;
|