Skip to main content

use_query_select

Function use_query_select 

Source
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))
where T: Clone + PartialEq + Send + Sync + 'static, U: 'static, E: Clone + Send + Sync + Debug + 'static, C: 'static, F: Fn(QuerySignal) -> Fut + Send + 'static, Fut: Future<Output = Result<T, E>> + Send + 'static,
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:

  1. Calls use_query to create/subscribe to the underlying QueryResource.
  2. Creates a MappedQueryResource<T, U, E> entity seeded with the current source data.
  3. 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 when MappedQueryResource::data() is called.

§Returns

A tuple of:

  • Entity<MappedQueryResource<T, U, E>> — the projected view entity
  • Entity<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