Skip to content

Commit 5a518cd

Browse files
Update docstrings for compare functions (#850)
Update the docstrings for the comparison functions passed to useMergedInfiniteQueries and mergeSortedArrays.
1 parent ad5b280 commit 5a518cd

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

src/hooks/use-merged-infinite-queries/use-merged-infinite-queries.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ import {
2525
* @param queries - Array of react-query Infinite Query configurations.
2626
* @param pageSize - Number of items to add to the result array when requesting new data.
2727
* @param flattenResponse - A function that takes the expected query response and flattens it into an array of items
28-
* @param compare - A comparison function used to sort and merge results.
29-
* The function should accept two arguments and return:
30-
* - A number > 0 if the second argument comes first.
31-
* - A number <= 0 if the first argument comes first.
32-
* - **Note:** The comparison logic must match the sorting logic used in the queries to maintain consistency.
28+
* @param compare - A comparison function used to determine the order of items. It should take two items and return:
29+
* - A positive number (> 0) if the second item should come before the first.
30+
* - Zero or a negative number (<= 0) if the first item should come before the second.
31+
* - This logic must match the sorting logic used in the queries to ensure consistency.
32+
* - For more details, see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#comparefn
3333
*
3434
* @returns A tuple [mergedQueryResults, queryResults]:
3535
* - `mergedQueryResults`: The merged and sorted results from all queries.

src/utils/merge-sorted-arrays.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
*
88
* @param sortedArrays - An array of sorted arrays to pick items from and merge.
99
* @param itemsCount - The number of items to pick from the sorted arrays.
10-
* @param compareFunc - A comparison function used to determine the order of items.
11-
* - If the function returns a number > 0, the first argument is considered the higher-priority candidate.
12-
* - If the function returns a number <= 0, the second argument is considered the higher-priority candidate.
13-
* **Note:** The comparison logic must align with the sorting logic of the input arrays to maintain consistency.
10+
* @param compareFunc - A comparison function used to determine the order of items. It should take two items and return:
11+
* - A positive number (> 0) if the second item should come before the first.
12+
* - Zero or a negative number (<= 0) if the first item should come before the second.
13+
* - This logic must match the sorting logic of the input arrays to ensure consistency.
14+
* - For more details, see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#comparefn
1415
*
1516
* @returns An object containing:
1617
* - `pointers`: An array of the last picked index from each input array.

0 commit comments

Comments
 (0)