pub fn use_query_select<T, U, E, C, F, Fut>(
options: impl Into<QueryOptions>,
transform: SelectTransform<T, U>,
fetcher: F,
cx: &mut Context<'_, C>,
) -> (Entity<MappedQueryResource<T, U, E>>, Entity<QueryResource<T, E>>, (Subscription, Subscription))Available on crate feature
hook only.Expand description
Subscribe to a query and project its data through a SelectTransform.
This is the “select” integration point for the hook layer (audit #3, HIGH finding). It:
- Calls
use_queryto create/subscribe to the underlyingQueryResource. - Creates a
MappedQueryResource<T, U, E>entity seeded with the current source data. - Observes the source entity so that every time it changes, the mapped
resource’s source data is updated from the fresh
QueryResource::data(). The transform itself is applied lazily whenMappedQueryResource::data()is called.
§Returns
A tuple of:
Entity<MappedQueryResource<T, U, E>>— the projected view entityEntity<QueryResource<T, E>>— the underlying query entity (for status, error, refetch, etc.)(Subscription, Subscription)— the query subscription and the mapped observer subscription. Store both to keep observations alive.
§Transform cost
The transform closure runs every time mapped.data() is called (no output
cache). For expensive transforms, cache the result:
use gpui_query::core::{MappedQueryResource, SelectTransform};
let count = mapped.read(cx).data(); // transform runs once
// reuse `count` below