Struct QueryClient

Source
pub struct QueryClient<Codec = RkyvCodec> { /* private fields */ }
Expand description

The QueryClient stores all query data, and is used to manage queries.

Should be provided via leptos context at the top of the app.

§Example

use leptos::prelude::*;
use leptos_fetch::QueryClient;

#[component]
pub fn App() -> impl IntoView {
   QueryClient::new().provide();
    // ...
}

#[component]
pub fn MyComponent() -> impl IntoView {
    let client: QueryClient = expect_context();
     // ...
}

Implementations§

Source§

impl QueryClient<RkyvCodec>

Source

pub fn new() -> Self

Creates a new QueryClient with the default codec: codee::string::JsonSerdeCodec.

Call QueryClient::set_codec() to set a different codec.

Call QueryClient::with_options() to set non-default options.

Source§

impl<Codec: 'static> QueryClient<Codec>

Source

pub fn provide(self) -> Self

Provide the client to leptos context.

use leptos_fetch::QueryClient;
use leptos::prelude::*;

QueryClient::new().provide();

let client: QueryClient = expect_context();
Source

pub fn set_codec<NewCodec>(self) -> QueryClient<NewCodec>

Applies to ssr only

It’s possible to use non-json codecs for streaming leptos resources from the backend. The default is codee::string::JsonSerdeCodec.

The current codee major version is 0.3 and will need to be imported in your project to customize the codec.

E.g. to use codee::binary::MsgpackSerdeCodec:

codee = { version = "0.3", features = ["msgpack_serde"] }

This is a generic type on the QueryClient, so when calling leptos::prelude::expect_context, this type must be specified when not using the default.

A useful pattern is to type alias the client with the custom codec for your whole app:

use codee::binary::MsgpackSerdeCodec;
use leptos::prelude::*;
use leptos_fetch::QueryClient;

type MyQueryClient = QueryClient<MsgpackSerdeCodec>;

// Create and provide to context to make accessible everywhere:
QueryClient::new().set_codec::<MsgpackSerdeCodec>().provide();

let client: MyQueryClient = expect_context();
Source

pub fn with_options(self, options: QueryOptions) -> Self

Set non-default options to apply to all queries.

These options will be combined with any options for a specific query scope.

Source

pub fn options(&self) -> QueryOptions

Read the base QueryOptions for this QueryClient.

These will be combined with any options for a specific query scope.

Source

pub fn local_resource<K, MaybeKey, V, M>( &self, query_scope: impl QueryScopeLocalTrait<K, V, M> + 'static, keyer: impl Fn() -> MaybeKey + 'static, ) -> LocalResource<MaybeKey::MappedValue>
where K: DebugIfDevtoolsEnabled + Hash + Clone + 'static, MaybeKey: QueryMaybeKey<K, V>, MaybeKey::MappedValue: DebugIfDevtoolsEnabled + Clone + 'static, V: DebugIfDevtoolsEnabled + Clone + 'static,

Query with LocalResource. Local resouces only load data on the client, so can be used with non-threadsafe/serializable data.

If a cached value exists but is stale, the cached value will be initially used, then refreshed in the background, updating once the new value is ready.

Source

pub fn arc_local_resource<K, MaybeKey, V, M>( &self, query_scope: impl QueryScopeLocalTrait<K, V, M> + 'static, keyer: impl Fn() -> MaybeKey + 'static, ) -> ArcLocalResource<MaybeKey::MappedValue>
where K: DebugIfDevtoolsEnabled + Hash + Clone + 'static, MaybeKey: QueryMaybeKey<K, V>, MaybeKey::MappedValue: DebugIfDevtoolsEnabled + Clone + 'static, V: DebugIfDevtoolsEnabled + Clone + 'static,

Query with ArcLocalResource. Local resouces only load data on the client, so can be used with non-threadsafe/serializable data.

If a cached value exists but is stale, the cached value will be initially used, then refreshed in the background, updating once the new value is ready.

Source

pub fn resource<K, MaybeKey, V, M>( &self, query_scope: impl QueryScopeTrait<K, V, M> + Send + Sync + 'static, keyer: impl Fn() -> MaybeKey + Send + Sync + 'static, ) -> Resource<MaybeKey::MappedValue, Codec>
where K: DebugIfDevtoolsEnabled + PartialEq + Hash + Clone + Send + Sync + 'static, MaybeKey: QueryMaybeKey<K, V>, MaybeKey::MappedValue: Clone + Send + Sync + 'static, V: DebugIfDevtoolsEnabled + Clone + Send + Sync + 'static, Codec: Encoder<MaybeKey::MappedValue> + Decoder<MaybeKey::MappedValue>, <Codec as Encoder<MaybeKey::MappedValue>>::Error: Debug, <Codec as Decoder<MaybeKey::MappedValue>>::Error: Debug, <<Codec as Decoder<MaybeKey::MappedValue>>::Encoded as FromEncodedStr>::DecodingError: Debug, <Codec as Encoder<MaybeKey::MappedValue>>::Encoded: IntoEncodedString, <Codec as Decoder<MaybeKey::MappedValue>>::Encoded: FromEncodedStr,

Query with Resource.

Resources must be serializable to potentially load in ssr and stream to the client.

Resources must be Send and Sync to be multithreaded in ssr.

If a cached value exists but is stale, the cached value will be initially used, then refreshed in the background, updating once the new value is ready.

Source

pub fn resource_blocking<K, MaybeKey, V, M>( &self, query_scope: impl QueryScopeTrait<K, V, M> + Send + Sync + 'static, keyer: impl Fn() -> MaybeKey + Send + Sync + 'static, ) -> Resource<MaybeKey::MappedValue, Codec>
where K: DebugIfDevtoolsEnabled + PartialEq + Hash + Clone + Send + Sync + 'static, MaybeKey: QueryMaybeKey<K, V>, MaybeKey::MappedValue: Clone + Send + Sync + 'static, V: DebugIfDevtoolsEnabled + Clone + Send + Sync + 'static, Codec: Encoder<MaybeKey::MappedValue> + Decoder<MaybeKey::MappedValue>, <Codec as Encoder<MaybeKey::MappedValue>>::Error: Debug, <Codec as Decoder<MaybeKey::MappedValue>>::Error: Debug, <<Codec as Decoder<MaybeKey::MappedValue>>::Encoded as FromEncodedStr>::DecodingError: Debug, <Codec as Encoder<MaybeKey::MappedValue>>::Encoded: IntoEncodedString, <Codec as Decoder<MaybeKey::MappedValue>>::Encoded: FromEncodedStr,

Query with a blocking Resource.

Resources must be serializable to potentially load in ssr and stream to the client.

Resources must be Send and Sync to be multithreaded in ssr.

If a cached value exists but is stale, the cached value will be initially used, then refreshed in the background, updating once the new value is ready.

Source

pub fn arc_resource<K, MaybeKey, V, M>( &self, query_scope: impl QueryScopeTrait<K, V, M> + Send + Sync + 'static, keyer: impl Fn() -> MaybeKey + Send + Sync + 'static, ) -> ArcResource<MaybeKey::MappedValue, Codec>
where K: DebugIfDevtoolsEnabled + PartialEq + Hash + Clone + Send + Sync + 'static, MaybeKey: QueryMaybeKey<K, V>, MaybeKey::MappedValue: Clone + Send + Sync + 'static, V: DebugIfDevtoolsEnabled + Clone + Send + Sync + 'static, Codec: Encoder<MaybeKey::MappedValue> + Decoder<MaybeKey::MappedValue>, <Codec as Encoder<MaybeKey::MappedValue>>::Error: Debug, <Codec as Decoder<MaybeKey::MappedValue>>::Error: Debug, <<Codec as Decoder<MaybeKey::MappedValue>>::Encoded as FromEncodedStr>::DecodingError: Debug, <Codec as Encoder<MaybeKey::MappedValue>>::Encoded: IntoEncodedString, <Codec as Decoder<MaybeKey::MappedValue>>::Encoded: FromEncodedStr,

Query with ArcResource.

Resources must be serializable to potentially load in ssr and stream to the client.

Resources must be Send and Sync to be multithreaded in ssr.

If a cached value exists but is stale, the cached value will be initially used, then refreshed in the background, updating once the new value is ready.

Source

pub fn arc_resource_blocking<K, MaybeKey, V, M>( &self, query_scope: impl QueryScopeTrait<K, V, M> + Send + Sync + 'static, keyer: impl Fn() -> MaybeKey + Send + Sync + 'static, ) -> ArcResource<MaybeKey::MappedValue, Codec>
where K: DebugIfDevtoolsEnabled + PartialEq + Hash + Clone + Send + Sync + 'static, MaybeKey: QueryMaybeKey<K, V>, MaybeKey::MappedValue: Clone + Send + Sync + 'static, V: DebugIfDevtoolsEnabled + Clone + Send + Sync + 'static, Codec: Encoder<MaybeKey::MappedValue> + Decoder<MaybeKey::MappedValue>, <Codec as Encoder<MaybeKey::MappedValue>>::Error: Debug, <Codec as Decoder<MaybeKey::MappedValue>>::Error: Debug, <<Codec as Decoder<MaybeKey::MappedValue>>::Encoded as FromEncodedStr>::DecodingError: Debug, <Codec as Encoder<MaybeKey::MappedValue>>::Encoded: IntoEncodedString, <Codec as Decoder<MaybeKey::MappedValue>>::Encoded: FromEncodedStr,

Query with a blocking ArcResource.

Resources must be serializable to potentially load in ssr and stream to the client.

Resources must be Send and Sync to be multithreaded in ssr.

If a cached value exists but is stale, the cached value will be initially used, then refreshed in the background, updating once the new value is ready.

Source

pub fn untrack_update_query(&self)

Prevent reactive updates being triggered from the current updater callback fn.

Call QueryClient::untrack_update_query in the callback of QueryClient::update_query to prevent resources being updated after the callback completes.

This is really useful when e.g:

  • you know nothing changes after reading the existing value in the callback
  • you don’t want resources/subs to react and rerender, given nothings changed.

This function is a noop outside the callbacks of:

Source

pub async fn prefetch_query<K, V, M>( &self, query_scope: impl QueryScopeTrait<K, V, M>, key: impl Borrow<K>, )
where K: DebugIfDevtoolsEnabled + Clone + Hash + Send + Sync + 'static, V: DebugIfDevtoolsEnabled + Clone + Send + Sync + 'static,

Prefetch a query and store it in the cache.

  • Entry doesn’t exist: fetched and stored in the cache.
  • Entry exists but stale: fetched and updated in the cache.
  • Entry exists but not stale: not refreshed, existing cache item remains.

If the cached query changes, active resources using the query will be updated.

Source

pub async fn prefetch_query_local<K, V, M>( &self, query_scope: impl QueryScopeLocalTrait<K, V, M>, key: impl Borrow<K>, )
where K: DebugIfDevtoolsEnabled + Clone + Hash + 'static, V: DebugIfDevtoolsEnabled + Clone + 'static,

Prefetch a non-threadsafe query and store it in the cache for this thread only.

  • Entry doesn’t exist: fetched and stored in the cache.
  • Entry exists but stale: fetched and updated in the cache.
  • Entry exists but not stale: not refreshed, existing cache item remains.

If the cached query changes, active resources using the query will be updated.

Source

pub async fn fetch_query<K, V, M>( &self, query_scope: impl QueryScopeTrait<K, V, M>, key: impl Borrow<K>, ) -> V
where K: DebugIfDevtoolsEnabled + Clone + Hash + Send + Sync + 'static, V: DebugIfDevtoolsEnabled + Clone + Send + Sync + 'static,

Fetch a query, store it in the cache and return it.

  • Entry doesn’t exist: fetched and stored in the cache.
  • Entry exists but stale: fetched and updated in the cache.
  • Entry exists but not stale: not refreshed, existing cache item remains.

If the cached query changes, active resources using the query will be updated.

Returns the up-to-date cached query.

Source

pub async fn fetch_query_local<K, V, M>( &self, query_scope: impl QueryScopeLocalTrait<K, V, M>, key: impl Borrow<K>, ) -> V
where K: DebugIfDevtoolsEnabled + Clone + Hash + 'static, V: DebugIfDevtoolsEnabled + Clone + 'static,

Fetch a non-threadsafe query, store it in the cache for this thread only and return it.

  • Entry doesn’t exist: fetched and stored in the cache.
  • Entry exists but stale: fetched and updated in the cache.
  • Entry exists but not stale: not refreshed, existing cache item remains.

If the cached query changes, active resources using the query will be updated.

Returns the up-to-date cached query.

Source

pub fn set_query<K, V, M>( &self, query_scope: impl QueryScopeTrait<K, V, M>, key: impl Borrow<K>, new_value: V, )
where K: DebugIfDevtoolsEnabled + Clone + Hash + Send + Sync + 'static, V: DebugIfDevtoolsEnabled + Clone + Send + Sync + 'static,

Set the value of a query in the cache. This cached value will be available from all threads and take priority over any locally cached value for this query.

Active resources using the query will be updated.

Source

pub fn set_query_local<K, V, M>( &self, query_scope: impl QueryScopeLocalTrait<K, V, M>, key: impl Borrow<K>, new_value: V, )
where K: DebugIfDevtoolsEnabled + Clone + Hash + 'static, V: DebugIfDevtoolsEnabled + Clone + 'static,

Set the value of a non-threadsafe query in the cache for this thread only. This cached value will only be available from this thread, the cache will return empty, unless a nonlocal value is set, from any other thread.

Active resources using the query will be updated.

Source

pub fn update_query<K, V, T, M>( &self, query_scope: impl QueryScopeLocalTrait<K, V, M>, key: impl Borrow<K>, modifier: impl FnOnce(Option<&mut V>) -> T, ) -> T
where K: DebugIfDevtoolsEnabled + Clone + Hash + 'static, V: DebugIfDevtoolsEnabled + Clone + 'static,

Synchronously update the value of a query in the cache with a callback.

Active resources using the query will be updated.

The callback takes Option<&mut V>, will be None if the value is not available in the cache.

If you want async and/or always get the value, use QueryClient::update_query_async/QueryClient::update_query_async_local.

Returns the output of the callback.

If you decide you don’t want to trigger resources and subscribers, e.g. if you know nothing changed, call QueryClient::untrack_update_query in the callback to prevent reactive updates.

Source

pub async fn update_query_async<'a, K, V, T, M>( &'a self, query_scope: impl QueryScopeTrait<K, V, M>, key: impl Borrow<K>, mapper: impl AsyncFnOnce(&mut V) -> T, ) -> T
where K: DebugIfDevtoolsEnabled + Clone + Hash + Send + Sync + 'static, V: DebugIfDevtoolsEnabled + Clone + Send + Sync + 'static,

Asynchronously map a threadsafe query in the cache from one value to another.

Unlike QueryClient::update_query, this will fetch the query first, if it doesn’t exist.

Active resources using the query will be updated.

Returns the output of the callback.

If you decide you don’t want to trigger resources and subscribers, e.g. if you know nothing changed, call QueryClient::untrack_update_query in the callback to prevent reactive updates.

Source

pub async fn update_query_async_local<'a, K, V, T, M>( &'a self, query_scope: impl QueryScopeLocalTrait<K, V, M>, key: impl Borrow<K>, mapper: impl AsyncFnOnce(&mut V) -> T, ) -> T
where K: DebugIfDevtoolsEnabled + Clone + Hash + 'static, V: DebugIfDevtoolsEnabled + Clone + 'static,

Asynchronously map a non-threadsafe query in the cache from one value to another.

Unlike QueryClient::update_query, this will fetch the query first, if it doesn’t exist.

Active resources using the query will be updated.

Returns the output of the callback.

If you decide you don’t want to trigger resources and subscribers, e.g. if you know nothing changed, call QueryClient::untrack_update_query in the callback to prevent reactive updates.

Source

pub fn get_cached_query<K, V, M>( &self, query_scope: impl QueryScopeLocalTrait<K, V, M>, key: impl Borrow<K>, ) -> Option<V>
where K: DebugIfDevtoolsEnabled + Hash + 'static, V: DebugIfDevtoolsEnabled + Clone + 'static,

Synchronously get a query from the cache, if it exists.

Source

pub fn query_exists<K, V, M>( &self, query_scope: impl QueryScopeLocalTrait<K, V, M>, key: impl Borrow<K>, ) -> bool
where K: DebugIfDevtoolsEnabled + Hash + 'static, V: DebugIfDevtoolsEnabled + 'static,

Synchronously check if a query exists in the cache.

Returns true if the query exists.

Source

pub fn subscribe_is_loading<K, MaybeKey, V, M>( &self, query_scope: impl QueryScopeLocalTrait<K, V, M>, keyer: impl Fn() -> MaybeKey + Send + Sync + 'static, ) -> Signal<bool>
where K: Hash + Send + Sync + 'static, MaybeKey: QueryMaybeKey<K, V>, MaybeKey::MappedValue: 'static, V: 'static,

Subscribe to the is_loading status of a query. The keyer function is reactive to changes in K.

This is true when the query is in the process of fetching data for the first time. This is in contrast to is_fetching, that is true whenever the query is fetching data, including when it’s refetching.

From a resource perspective:

  • is_loading=true, the resource will be in a pending state until ready and implies is_fetching=true
  • is_fetching=true + is_loading=false means the resource is showing previous data, and will update once new data finishes refetching
  • is_fetching=false means the resource is showing the latest data and implies is_loading=false
Source

pub fn subscribe_is_loading_local<K, MaybeKey, V, M>( &self, query_scope: impl QueryScopeLocalTrait<K, V, M>, keyer: impl Fn() -> MaybeKey + 'static, ) -> Signal<bool>
where K: Hash + 'static, MaybeKey: QueryMaybeKey<K, V>, MaybeKey::MappedValue: 'static, V: 'static,

Subscribe to the is_loading status of a query with a non-threadsafe key. The keyer function is reactive to changes in K.

This is true when the query is in the process of fetching data for the first time. This is in contrast to is_fetching, that is true whenever the query is fetching data, including when it’s refetching.

From a resource perspective:

  • is_loading=true, the resource will be in a pending state until ready and implies is_fetching=true
  • is_fetching=true + is_loading=false means the resource is showing previous data, and will update once new data finishes refetching
  • is_fetching=false means the resource is showing the latest data and implies is_loading=false
Source

pub fn subscribe_is_loading_arc_local<K, MaybeKey, V, M>( &self, query_scope: impl QueryScopeLocalTrait<K, V, M>, keyer: impl Fn() -> MaybeKey + 'static, ) -> ArcSignal<bool>
where K: Hash + 'static, MaybeKey: QueryMaybeKey<K, V>, MaybeKey::MappedValue: 'static, V: 'static,

Subscribe to the is_loading status of a query with a non-threadsafe key. The keyer function is reactive to changes in K.

This is true when the query is in the process of fetching data for the first time. This is in contrast to is_fetching, that is true whenever the query is fetching data, including when it’s refetching.

From a resource perspective:

  • is_loading=true, the resource will be in a pending state until ready and implies is_fetching=true
  • is_fetching=true + is_loading=false means the resource is showing previous data, and will update once new data finishes refetching
  • is_fetching=false means the resource is showing the latest data and implies is_loading=false
Source

pub fn subscribe_is_loading_arc<K, MaybeKey, V, M>( &self, query_scope: impl QueryScopeLocalTrait<K, V, M>, keyer: impl Fn() -> MaybeKey + Send + Sync + 'static, ) -> ArcSignal<bool>
where K: Hash + Send + Sync + 'static, MaybeKey: QueryMaybeKey<K, V>, MaybeKey::MappedValue: 'static, V: 'static,

Subscribe to the is_loading status of a query. The keyer function is reactive to changes in K.

This is true when the query is in the process of fetching data for the first time. This is in contrast to is_fetching, that is true whenever the query is fetching data, including when it’s refetching.

From a resource perspective:

  • is_loading=true, the resource will be in a pending state until ready and implies is_fetching=true
  • is_fetching=true + is_loading=false means the resource is showing previous data, and will update once new data finishes refetching
  • is_fetching=false means the resource is showing the latest data and implies is_loading=false
Source

pub fn subscribe_is_fetching<K, MaybeKey, V, M>( &self, query_scope: impl QueryScopeLocalTrait<K, V, M>, keyer: impl Fn() -> MaybeKey + Send + Sync + 'static, ) -> Signal<bool>
where K: Hash + Send + Sync + 'static, MaybeKey: QueryMaybeKey<K, V>, MaybeKey::MappedValue: 'static, V: 'static,

Subscribe to the is_fetching status of a query. The keyer function is reactive to changes in K.

This is true is true whenever the query is fetching data, including when it’s refetching. This is in contrast to is_loading, that is true when the query is in the process of fetching data for the first time only.

From a resource perspective:

  • is_loading=true, the resource will be in a pending state until ready and implies is_fetching=true
  • is_fetching=true + is_loading=false means the resource is showing previous data, and will update once new data finishes refetching
  • is_fetching=false means the resource is showing the latest data and implies is_loading=false
Source

pub fn subscribe_is_fetching_local<K, MaybeKey, V, M>( &self, query_scope: impl QueryScopeLocalTrait<K, V, M>, keyer: impl Fn() -> MaybeKey + 'static, ) -> Signal<bool>
where K: Hash + 'static, MaybeKey: QueryMaybeKey<K, V>, MaybeKey::MappedValue: 'static, V: 'static,

Subscribe to the is_fetching status of a query with a non-threadsafe key. The keyer function is reactive to changes in K.

This is true is true whenever the query is fetching data, including when it’s refetching. This is in contrast to is_loading, that is true when the query is in the process of fetching data for the first time only.

From a resource perspective:

  • is_loading=true, the resource will be in a pending state until ready and implies is_fetching=true
  • is_fetching=true + is_loading=false means the resource is showing previous data, and will update once new data finishes refetching
  • is_fetching=false means the resource is showing the latest data and implies is_loading=false
Source

pub fn subscribe_is_fetching_arc_local<K, MaybeKey, V, M>( &self, query_scope: impl QueryScopeLocalTrait<K, V, M>, keyer: impl Fn() -> MaybeKey + 'static, ) -> ArcSignal<bool>
where K: Hash + 'static, MaybeKey: QueryMaybeKey<K, V>, MaybeKey::MappedValue: 'static, V: 'static,

Subscribe to the is_fetching status of a query with a non-threadsafe key. The keyer function is reactive to changes in K.

This is true is true whenever the query is fetching data, including when it’s refetching. This is in contrast to is_loading, that is true when the query is in the process of fetching data for the first time only.

From a resource perspective:

  • is_loading=true, the resource will be in a pending state until ready and implies is_fetching=true
  • is_fetching=true + is_loading=false means the resource is showing previous data, and will update once new data finishes refetching
  • is_fetching=false means the resource is showing the latest data and implies is_loading=false
Source

pub fn subscribe_is_fetching_arc<K, MaybeKey, V, M>( &self, query_scope: impl QueryScopeLocalTrait<K, V, M>, keyer: impl Fn() -> MaybeKey + Send + Sync + 'static, ) -> ArcSignal<bool>
where K: Hash + Send + Sync + 'static, MaybeKey: QueryMaybeKey<K, V>, MaybeKey::MappedValue: 'static, V: 'static,

Subscribe to the is_fetching status of a query. The keyer function is reactive to changes in K.

This is true is true whenever the query is fetching data, including when it’s refetching. This is in contrast to is_loading, that is true when the query is in the process of fetching data for the first time only.

From a resource perspective:

  • is_loading=true, the resource will be in a pending state until ready and implies is_fetching=true
  • is_fetching=true + is_loading=false means the resource is showing previous data, and will update once new data finishes refetching
  • is_fetching=false means the resource is showing the latest data and implies is_loading=false
Source

pub fn subscribe_value<K, MaybeKey, V, M>( &self, query_scope: impl QueryScopeTrait<K, V, M>, keyer: impl Fn() -> MaybeKey + Send + Sync + 'static, ) -> Signal<Option<V>>
where K: DebugIfDevtoolsEnabled + Hash + Send + Sync + 'static, MaybeKey: QueryMaybeKey<K, V>, MaybeKey::MappedValue: DebugIfDevtoolsEnabled + Clone + Send + Sync + 'static, V: DebugIfDevtoolsEnabled + Clone + Send + Sync + 'static,

Subscribe to the value of a query. The keyer function is reactive to changes in K.

This will update whenever the query is created, removed, updated, refetched or set.

Compared to a resource:

  • This will not trigger a fetch of a query, if it’s not in the cache, this will be None.
Source

pub fn subscribe_value_local<K, MaybeKey, V, M>( &self, query_scope: impl QueryScopeLocalTrait<K, V, M>, keyer: impl Fn() -> MaybeKey + 'static, ) -> Signal<Option<V>, LocalStorage>
where K: DebugIfDevtoolsEnabled + Hash + 'static, MaybeKey: QueryMaybeKey<K, V>, MaybeKey::MappedValue: DebugIfDevtoolsEnabled + Clone + 'static, V: DebugIfDevtoolsEnabled + Clone + 'static,

Subscribe to the value of a non-threadsafe query. The keyer function is reactive to changes in K.

This will update whenever the query is created, removed, updated, refetched or set.

Compared to a resource:

  • This will not trigger a fetch of a query, if it’s not in the cache, this will be None.
Source

pub fn subscribe_value_arc_local<K, MaybeKey, V, M>( &self, query_scope: impl QueryScopeLocalTrait<K, V, M>, keyer: impl Fn() -> MaybeKey + 'static, ) -> ArcLocalSignal<Option<V>>
where K: DebugIfDevtoolsEnabled + Hash + 'static, MaybeKey: QueryMaybeKey<K, V>, MaybeKey::MappedValue: DebugIfDevtoolsEnabled + Clone + 'static, V: DebugIfDevtoolsEnabled + Clone + 'static,

Subscribe to the value of a non-threadsafe query. The keyer function is reactive to changes in K.

This will update whenever the query is created, removed, updated, refetched or set.

Compared to a resource:

  • This will not trigger a fetch of a query, if it’s not in the cache, this will be None.
Source

pub fn subscribe_value_arc<K, MaybeKey, V, M>( &self, query_scope: impl QueryScopeTrait<K, V, M>, keyer: impl Fn() -> MaybeKey + Send + Sync + 'static, ) -> ArcSignal<Option<V>>
where K: DebugIfDevtoolsEnabled + Hash + Send + Sync + 'static, MaybeKey: QueryMaybeKey<K, V>, MaybeKey::MappedValue: DebugIfDevtoolsEnabled + Clone + Send + Sync + 'static, V: DebugIfDevtoolsEnabled + Clone + Send + Sync + 'static,

Subscribe to the value of a query. The keyer function is reactive to changes in K.

This will update whenever the query is created, removed, updated, refetched or set.

Compared to a resource:

  • This will not trigger a fetch of a query, if it’s not in the cache, this will be None.
Source

pub fn invalidate_query<K, V, M>( &self, query_scope: impl QueryScopeLocalTrait<K, V, M>, key: impl Borrow<K>, ) -> bool
where K: DebugIfDevtoolsEnabled + Hash + 'static, V: DebugIfDevtoolsEnabled + Clone + 'static,

Mark a query as stale.

Any active resources will refetch in the background, replacing them when ready.

Source

pub fn invalidate_queries<K, V, KRef, M>( &self, query_scope: impl QueryScopeLocalTrait<K, V, M>, keys: impl IntoIterator<Item = KRef>, ) -> Vec<KRef>
where K: DebugIfDevtoolsEnabled + Hash + 'static, V: DebugIfDevtoolsEnabled + Clone + 'static, KRef: Borrow<K>,

Mark multiple queries of a specific type as stale.

Any active resources will refetch in the background, replacing them when ready.

Source

pub fn invalidate_queries_with_predicate<K, V, M>( &self, query_scope: impl QueryScopeLocalTrait<K, V, M>, should_invalidate: impl Fn(&K) -> bool, )
where K: DebugIfDevtoolsEnabled + Hash + 'static, V: DebugIfDevtoolsEnabled + Clone + 'static,

Mark one or more queries of a specific type as stale with a callback.

When the callback returns true, the specific query will be invalidated.

Any active resources subscribing to that query will refetch in the background, replacing them when ready.

Source

pub fn invalidate_query_scope<K, V, M>( &self, query_scope: impl QueryScopeLocalTrait<K, V, M>, )
where K: Hash + 'static, V: Clone + 'static,

Mark all queries of a specific type as stale.

Any active resources will refetch in the background, replacing them when ready.

Source

pub fn invalidate_all_queries(&self)

Mark all queries as stale.

Any active resources will refetch in the background, replacing them when ready.

Source

pub fn clear(&self)

Empty the cache, note QueryClient::invalidate_all_queries is preferred in most cases.

All active resources will instantly revert to pending until the new query finishes refetching.

QueryClient::invalidate_all_queries on the other hand, will only refetch active queries in the background, replacing them when ready.

Trait Implementations§

Source§

impl<Codec: 'static> Clone for QueryClient<Codec>

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Codec> Debug for QueryClient<Codec>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for QueryClient<RkyvCodec>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<Codec: 'static> Copy for QueryClient<Codec>

Auto Trait Implementations§

§

impl<Codec> Freeze for QueryClient<Codec>

§

impl<Codec> RefUnwindSafe for QueryClient<Codec>
where Codec: RefUnwindSafe,

§

impl<Codec> Send for QueryClient<Codec>

§

impl<Codec> Sync for QueryClient<Codec>

§

impl<Codec> Unpin for QueryClient<Codec>
where Codec: Unpin,

§

impl<Codec> UnwindSafe for QueryClient<Codec>
where Codec: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<E, T, Request, Encoding> FromReq<Patch<Encoding>, Request, E> for T
where Request: Req<E> + Send + 'static, Encoding: Decodes<T>, E: FromServerFnError,

Source§

async fn from_req(req: Request) -> Result<T, E>

Attempts to deserialize the arguments from a request.
Source§

impl<E, T, Request, Encoding> FromReq<Post<Encoding>, Request, E> for T
where Request: Req<E> + Send + 'static, Encoding: Decodes<T>, E: FromServerFnError,

Source§

async fn from_req(req: Request) -> Result<T, E>

Attempts to deserialize the arguments from a request.
Source§

impl<E, T, Request, Encoding> FromReq<Put<Encoding>, Request, E> for T
where Request: Req<E> + Send + 'static, Encoding: Decodes<T>, E: FromServerFnError,

Source§

async fn from_req(req: Request) -> Result<T, E>

Attempts to deserialize the arguments from a request.
Source§

impl<E, Encoding, Response, T> FromRes<Patch<Encoding>, Response, E> for T
where Response: ClientRes<E> + Send, Encoding: Decodes<T>, E: FromServerFnError,

Source§

async fn from_res(res: Response) -> Result<T, E>

Attempts to deserialize the outputs from a response.
Source§

impl<E, Encoding, Response, T> FromRes<Post<Encoding>, Response, E> for T
where Response: ClientRes<E> + Send, Encoding: Decodes<T>, E: FromServerFnError,

Source§

async fn from_res(res: Response) -> Result<T, E>

Attempts to deserialize the outputs from a response.
Source§

impl<E, Encoding, Response, T> FromRes<Put<Encoding>, Response, E> for T
where Response: ClientRes<E> + Send, Encoding: Decodes<T>, E: FromServerFnError,

Source§

async fn from_res(res: Response) -> Result<T, E>

Attempts to deserialize the outputs from a response.
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<E, T, Encoding, Request> IntoReq<Patch<Encoding>, Request, E> for T
where Request: ClientReq<E>, Encoding: Encodes<T>, E: FromServerFnError,

Source§

fn into_req(self, path: &str, accepts: &str) -> Result<Request, E>

Attempts to serialize the arguments into an HTTP request.
Source§

impl<E, T, Encoding, Request> IntoReq<Post<Encoding>, Request, E> for T
where Request: ClientReq<E>, Encoding: Encodes<T>, E: FromServerFnError,

Source§

fn into_req(self, path: &str, accepts: &str) -> Result<Request, E>

Attempts to serialize the arguments into an HTTP request.
Source§

impl<E, T, Encoding, Request> IntoReq<Put<Encoding>, Request, E> for T
where Request: ClientReq<E>, Encoding: Encodes<T>, E: FromServerFnError,

Source§

fn into_req(self, path: &str, accepts: &str) -> Result<Request, E>

Attempts to serialize the arguments into an HTTP request.
Source§

impl<E, Response, Encoding, T> IntoRes<Patch<Encoding>, Response, E> for T
where Response: TryRes<E>, Encoding: Encodes<T>, E: FromServerFnError + Send, T: Send,

Source§

async fn into_res(self) -> Result<Response, E>

Attempts to serialize the output into an HTTP response.
Source§

impl<E, Response, Encoding, T> IntoRes<Post<Encoding>, Response, E> for T
where Response: TryRes<E>, Encoding: Encodes<T>, E: FromServerFnError + Send, T: Send,

Source§

async fn into_res(self) -> Result<Response, E>

Attempts to serialize the output into an HTTP response.
Source§

impl<E, Response, Encoding, T> IntoRes<Put<Encoding>, Response, E> for T
where Response: TryRes<E>, Encoding: Encodes<T>, E: FromServerFnError + Send, T: Send,

Source§

async fn into_res(self) -> Result<Response, E>

Attempts to serialize the output into an HTTP response.
Source§

impl<T> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
Source§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

Source§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
Source§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
Source§

impl<T> SerializableKey for T

Source§

fn ser_key(&self) -> String

Serializes the key to a unique string. Read more
Source§

impl<T> StorageAccess<T> for T

Source§

fn as_borrowed(&self) -> &T

Borrows the value.
Source§

fn into_taken(self) -> T

Takes the value.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> ErasedDestructor for T
where T: 'static,