@relax.js/core 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/collections/DataLoader.d.ts +51 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interface for loading paginated data from a data source.
|
|
3
|
+
* Implement this interface to provide data to table or list components
|
|
4
|
+
* that support pagination and sorting.
|
|
5
|
+
*
|
|
6
|
+
* Used by components like `r-table` to fetch data on demand as users
|
|
7
|
+
* navigate through pages or change sort order.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* // Implement for an API-backed data source
|
|
11
|
+
* class UserDataLoader implements DataLoader {
|
|
12
|
+
* async load(options) {
|
|
13
|
+
* const params = new URLSearchParams({
|
|
14
|
+
* page: options.page.toString(),
|
|
15
|
+
* pageSize: options.pageSize.toString(),
|
|
16
|
+
* sort: JSON.stringify(options.sort)
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* const response = await fetch(`/api/users?${params}`);
|
|
20
|
+
* return response.json();
|
|
21
|
+
* }
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* // Use with a table component
|
|
26
|
+
* const loader: DataLoader = new UserDataLoader();
|
|
27
|
+
* const result = await loader.load({ page: 1, pageSize: 25, sort: [] });
|
|
28
|
+
* table.render(result.rows);
|
|
29
|
+
*/
|
|
30
|
+
export interface DataLoader {
|
|
31
|
+
/**
|
|
32
|
+
* Loads a page of data with optional sorting.
|
|
33
|
+
*
|
|
34
|
+
* @param options - The loading options
|
|
35
|
+
* @param options.page - The 1-based page number to load
|
|
36
|
+
* @param options.pageSize - Number of rows per page
|
|
37
|
+
* @param options.sort - Array of sort specifications
|
|
38
|
+
* @returns Promise resolving to rows and total count for pagination
|
|
39
|
+
*/
|
|
40
|
+
load(options: {
|
|
41
|
+
page: number;
|
|
42
|
+
pageSize: number;
|
|
43
|
+
sort: {
|
|
44
|
+
column: string;
|
|
45
|
+
direction: 'asc' | 'desc';
|
|
46
|
+
}[];
|
|
47
|
+
}): Promise<{
|
|
48
|
+
rows: Record<string, any>[];
|
|
49
|
+
totalCount: number;
|
|
50
|
+
}>;
|
|
51
|
+
}
|
package/dist/index.d.ts
CHANGED