Skip to content
Source
Sign inSign up
TanStack/db

Callback to inform about loadSubset deduplication #694

Mergedkevin-dp(GitHub profile, opens in a new tab)merged 6 commits intoquery-driven-sync fromrefs/pull/694/headmerged by samwillis(GitHub profile, opens in a new tab)

Showing 4 changed files with 38 additions and 9 deletions (loading 1).

x
0 of 4 viewed, 4 left
5 additions and 0 deletions.changeset/two-lamps-wave.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+"@tanstack/db": patch
+---
+​
+Adds an onDeduplicate callback on the DeduplicatedLoadSubset class which is called when a loadSubset call is deduplicated
25 additions and 5 deletionspackages/db/src/query/subset-dedupe.tsModified
View file
@@ -12,8 +12,15 @@
* Tracks what data has been loaded and avoids redundant calls by applying
* subset logic to predicates.
+ * @param opts - The options for the DeduplicatedLoadSubset
+ * @param opts.loadSubset - The underlying loadSubset function to wrap
+ * @param opts.onDeduplicate - An optional callback function that is invoked when a loadSubset call is deduplicated.
+ * If the call is deduplicated because the requested data is being loaded by an inflight request,
+ * then this callback is invoked when the inflight request completes successfully and the data is fully loaded.
+ * This callback is useful if you need to track rows per query, in which case you can't ignore deduplicated calls
+ * because you need to know which rows were loaded for each query.
* @example
- * const dedupe = new DeduplicatedLoadSubset(myLoadSubset)
+ * const dedupe = new DeduplicatedLoadSubset({ loadSubset: myLoadSubset, onDeduplicate: (opts) => console.log(`Call was deduplicated:`, opts) })
* // First call - fetches data
* await dedupe.loadSubset({ where: gt(ref('age'), val(10)) })