Skip to content
Source
Sign inSign up
TanStack/db

Add getOptimisticInfo() method to track optimistic state per record #660

ClosedKyleAMathews(GitHub profile, opens in a new tab)wants to merge 2 commits intomain fromadd-getOptimisticInfoopened

Showing 5 changed files with 93 additions and 0 deletions (loading 2).

x
0 of 5 viewed, 5 left
5 additions and 0 deletions.changeset/cool-cups-argue.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+"@tanstack/db": patch
+---
+​
+Add `getOptimisticInfo()` method to track optimistic state per record. Returns metadata including `isOptimistic` flag, original/modified states, changes delta, and active mutations array for building UI features like loading badges and diff views.
33 additions and 0 deletionspackages/db/src/collection/index.tsModified
View file
@@ -27,6 +27,7 @@
NonSingleResult,
OnLoadMoreOptions,
OperationConfig,
+ OptimisticInfo,
SingleResult,
SubscribeChangesOptions,
Transaction as TransactionType,
@@ -398,6 +399,38 @@
​
/**
+ * Get optimistic state information for a record
+ * @param key - The key of the record to check
+ * @returns OptimisticInfo object with details about optimistic mutations, or undefined if record doesn't exist