Expand description
rs-query: TanStack Query-inspired data fetching for GPUI
§Features
- Declarative queries - Define once, auto-cache
- spawn_query/spawn_mutation - One-liner async execution
- Stale-while-revalidate - Show cached data while fetching
- Automatic retries - Exponential backoff for transient failures
- Cache invalidation - Hierarchical key patterns
§Example
ⓘ
use rs_query::{QueryClient, QueryKey, QueryState, Query, spawn_query};
// Define a query
let query = Query::new(QueryKey::new("users"), || async {
fetch_users().await
});
// Execute with automatic state management
spawn_query(cx, &client, &query, |this, state, cx| {
match state {
QueryState::Success(users) => this.users = users,
QueryState::Error { error, .. } => this.error = Some(error),
_ => {}
}
cx.notify();
});Structs§
- Mutation
- A mutation definition.
- Query
- A query definition.
- Query
Client - Central query client managing cache and query execution.
- Query
Key - A hierarchical query key for cache lookup and invalidation.
- Query
Options - Configuration options for a query
- Retry
Config - Retry configuration with exponential backoff
Enums§
- Mutation
State - Mutation state
- Query
Error - Errors that can occur during query/mutation operations
- Query
State - Represents the state of a query.
- Refetch
OnMount - When to refetch on mount
Functions§
- spawn_
mutation - Execute a mutation with automatic cache invalidation.
- spawn_
query - Execute a query using GPUI’s executor.