-
Notifications
You must be signed in to change notification settings - Fork 160
Add QueryObserver state utility methods to QueryCollectionUtils #742
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
KyleAMathews
merged 7 commits into
main
from
claude/add-query-observer-utils-011CUfe3K9sLFToVas2AHHh5
Nov 5, 2025
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f8fd37f
feat: Add QueryObserver state utilities and convert error utils to ge…
claude 17adcff
refactor: Extract QueryCollectionUtilsImpl class from closure
KyleAMathews 75aeb32
Merge origin/main into claude/add-query-observer-utils
KyleAMathews 06f4c19
chore: Update generated docs
KyleAMathews 09be8e2
chore: Re-generate documentation after build
KyleAMathews 3b4a50b
Merge origin/main into claude/add-query-observer-utils
KyleAMathews 50c5d1a
docs: Fix outdated comment about closure usage
KyleAMathews File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| --- | ||
| "@tanstack/query-db-collection": minor | ||
| "@tanstack/db": patch | ||
| --- | ||
|
|
||
| Add QueryObserver state utilities and convert error utils to getters | ||
|
|
||
| Exposes TanStack Query's QueryObserver state through QueryCollectionUtils, providing visibility into sync status beyond just error states. Also converts existing error state utilities from methods to getters for consistency with TanStack DB/Query patterns. | ||
|
|
||
| **Breaking Changes:** | ||
|
|
||
| - `lastError()`, `isError()`, and `errorCount()` are now getters instead of methods | ||
| - Before: `collection.utils.lastError()` | ||
| - After: `collection.utils.lastError` | ||
|
|
||
| **New Utilities:** | ||
|
|
||
| - `isFetching` - Check if query is currently fetching (initial or background) | ||
| - `isRefetching` - Check if query is refetching in background | ||
| - `isLoading` - Check if query is loading for first time | ||
| - `dataUpdatedAt` - Get timestamp of last successful data update | ||
| - `fetchStatus` - Get current fetch status ('fetching' | 'paused' | 'idle') | ||
|
|
||
| **Use Cases:** | ||
|
|
||
| - Show loading indicators during background refetches | ||
| - Implement "Last updated X minutes ago" UI patterns | ||
| - Better understanding of query sync behavior | ||
|
|
||
| **Example Usage:** | ||
|
|
||
| ```ts | ||
| const collection = queryCollectionOptions({ | ||
| // ... config | ||
| }) | ||
|
|
||
| // Check sync status | ||
| if (collection.utils.isFetching) { | ||
| console.log("Syncing with server...") | ||
| } | ||
|
|
||
| if (collection.utils.isRefetching) { | ||
| console.log("Background refresh in progress") | ||
| } | ||
|
|
||
| // Show last update time | ||
| const lastUpdate = new Date(collection.utils.dataUpdatedAt) | ||
| console.log(`Last synced: ${lastUpdate.toLocaleTimeString()}`) | ||
|
|
||
| // Check error state (now using getters) | ||
| if (collection.utils.isError) { | ||
| console.error("Sync failed:", collection.utils.lastError) | ||
| console.log(`Failed ${collection.utils.errorCount} times`) | ||
| } | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.