Skip to content
Source
Sign inSign up
TanStack/db

feat: Add flexible matching strategies for electric-db-collection (#402) #499

MergedKyleAMathewsmerged 23 commits intomain fromrefs/pull/499/headmerged by KyleAMathews

Showing 6 changed files with 47 additions and 0 deletions (loading 5).

x
0 of 6 viewed, 6 left
47 additions and 0 deletions.changeset/poor-wasps-stand.mdAdded
View file
@@ -0,0 +1,47 @@
+---
+"@tanstack/electric-db-collection": patch
+---
+​
+feat: Add awaitMatch utility and reduce default timeout (#402)
+​
+Adds a new `awaitMatch` utility function to support custom synchronization matching logic when transaction IDs (txids) are not available. Also reduces the default timeout for `awaitTxId` from 30 seconds to 5 seconds for faster feedback.
+​
+**New Features:**
+​
+- New utility method: `collection.utils.awaitMatch(matchFn, timeout?)` - Wait for custom match logic
+- Export `isChangeMessage` and `isControlMessage` helper functions for custom match functions
+- Type: `MatchFunction<T>` for custom match functions
+​
+**Changes:**
+​
+- Default timeout for `awaitTxId` reduced from 30 seconds to 5 seconds
+​
+**Example Usage:**
+​
+```typescript
+import { isChangeMessage } from "@tanstack/electric-db-collection"
+​
+const todosCollection = createCollection(
+ electricCollectionOptions({
+ onInsert: async ({ transaction, collection }) => {
+ const newItem = transaction.mutations[0].modified
+ await api.todos.create(newItem)
+​
+ // Wait for sync using custom match logic