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>
impl QueryClient<RkyvCodec>
Sourcepub fn new() -> Self
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>
impl<Codec: 'static> QueryClient<Codec>
Sourcepub fn provide(self) -> Self
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();
Sourcepub fn set_codec<NewCodec>(self) -> QueryClient<NewCodec>
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();
Sourcepub fn with_options(self, options: QueryOptions) -> Self
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.
Sourcepub fn options(&self) -> QueryOptions
pub fn options(&self) -> QueryOptions
Read the base QueryOptions
for this QueryClient
.
These will be combined with any options for a specific query scope.
Sourcepub fn local_resource<K, MaybeKey, V, M>(
&self,
query_scope: impl QueryScopeLocalTrait<K, V, M> + 'static,
keyer: impl Fn() -> MaybeKey + 'static,
) -> LocalResource<MaybeKey::MappedValue>
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>
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.
Sourcepub 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>
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>
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.
Sourcepub 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,
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.
Sourcepub 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,
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.
Sourcepub 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,
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.
Sourcepub 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,
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.
Sourcepub fn untrack_update_query(&self)
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:
Sourcepub async fn prefetch_query<K, V, M>(
&self,
query_scope: impl QueryScopeTrait<K, V, M>,
key: impl Borrow<K>,
)
pub async fn prefetch_query<K, V, M>( &self, query_scope: impl QueryScopeTrait<K, V, M>, key: impl Borrow<K>, )
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.
Sourcepub async fn prefetch_query_local<K, V, M>(
&self,
query_scope: impl QueryScopeLocalTrait<K, V, M>,
key: impl Borrow<K>,
)
pub async fn prefetch_query_local<K, V, M>( &self, query_scope: impl QueryScopeLocalTrait<K, V, M>, key: impl Borrow<K>, )
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.
Sourcepub async fn fetch_query<K, V, M>(
&self,
query_scope: impl QueryScopeTrait<K, V, M>,
key: impl Borrow<K>,
) -> V
pub async fn fetch_query<K, V, M>( &self, query_scope: impl QueryScopeTrait<K, V, M>, key: impl Borrow<K>, ) -> V
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.
Sourcepub async fn fetch_query_local<K, V, M>(
&self,
query_scope: impl QueryScopeLocalTrait<K, V, M>,
key: impl Borrow<K>,
) -> V
pub async fn fetch_query_local<K, V, M>( &self, query_scope: impl QueryScopeLocalTrait<K, V, M>, key: impl Borrow<K>, ) -> V
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.
Sourcepub fn set_query<K, V, M>(
&self,
query_scope: impl QueryScopeTrait<K, V, M>,
key: impl Borrow<K>,
new_value: V,
)
pub fn set_query<K, V, M>( &self, query_scope: impl QueryScopeTrait<K, V, M>, key: impl Borrow<K>, new_value: V, )
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.
Sourcepub fn set_query_local<K, V, M>(
&self,
query_scope: impl QueryScopeLocalTrait<K, V, M>,
key: impl Borrow<K>,
new_value: V,
)
pub fn set_query_local<K, V, M>( &self, query_scope: impl QueryScopeLocalTrait<K, V, M>, key: impl Borrow<K>, new_value: V, )
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.
Sourcepub 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
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
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.
Sourcepub 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
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
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.
Sourcepub 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
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
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.
Sourcepub fn get_cached_query<K, V, M>(
&self,
query_scope: impl QueryScopeLocalTrait<K, V, M>,
key: impl Borrow<K>,
) -> Option<V>
pub fn get_cached_query<K, V, M>( &self, query_scope: impl QueryScopeLocalTrait<K, V, M>, key: impl Borrow<K>, ) -> Option<V>
Synchronously get a query from the cache, if it exists.
Sourcepub fn query_exists<K, V, M>(
&self,
query_scope: impl QueryScopeLocalTrait<K, V, M>,
key: impl Borrow<K>,
) -> boolwhere
K: DebugIfDevtoolsEnabled + Hash + 'static,
V: DebugIfDevtoolsEnabled + 'static,
pub fn query_exists<K, V, M>(
&self,
query_scope: impl QueryScopeLocalTrait<K, V, M>,
key: impl Borrow<K>,
) -> boolwhere
K: DebugIfDevtoolsEnabled + Hash + 'static,
V: DebugIfDevtoolsEnabled + 'static,
Synchronously check if a query exists in the cache.
Returns true
if the query exists.
Sourcepub 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>
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>
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 impliesis_fetching=true
is_fetching=true
+is_loading=false
means the resource is showing previous data, and will update once new data finishes refetchingis_fetching=false
means the resource is showing the latest data and impliesis_loading=false
Sourcepub 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,
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 impliesis_fetching=true
is_fetching=true
+is_loading=false
means the resource is showing previous data, and will update once new data finishes refetchingis_fetching=false
means the resource is showing the latest data and impliesis_loading=false
Sourcepub 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,
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 impliesis_fetching=true
is_fetching=true
+is_loading=false
means the resource is showing previous data, and will update once new data finishes refetchingis_fetching=false
means the resource is showing the latest data and impliesis_loading=false
Sourcepub 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>
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>
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 impliesis_fetching=true
is_fetching=true
+is_loading=false
means the resource is showing previous data, and will update once new data finishes refetchingis_fetching=false
means the resource is showing the latest data and impliesis_loading=false
Sourcepub 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>
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>
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 impliesis_fetching=true
is_fetching=true
+is_loading=false
means the resource is showing previous data, and will update once new data finishes refetchingis_fetching=false
means the resource is showing the latest data and impliesis_loading=false
Sourcepub 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,
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 impliesis_fetching=true
is_fetching=true
+is_loading=false
means the resource is showing previous data, and will update once new data finishes refetchingis_fetching=false
means the resource is showing the latest data and impliesis_loading=false
Sourcepub 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,
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 impliesis_fetching=true
is_fetching=true
+is_loading=false
means the resource is showing previous data, and will update once new data finishes refetchingis_fetching=false
means the resource is showing the latest data and impliesis_loading=false
Sourcepub 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>
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>
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 impliesis_fetching=true
is_fetching=true
+is_loading=false
means the resource is showing previous data, and will update once new data finishes refetchingis_fetching=false
means the resource is showing the latest data and impliesis_loading=false
Sourcepub 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>>
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>>
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
.
Sourcepub 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>
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>
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
.
Sourcepub 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>>
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>>
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
.
Sourcepub 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>>
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>>
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
.
Sourcepub fn invalidate_query<K, V, M>(
&self,
query_scope: impl QueryScopeLocalTrait<K, V, M>,
key: impl Borrow<K>,
) -> bool
pub fn invalidate_query<K, V, M>( &self, query_scope: impl QueryScopeLocalTrait<K, V, M>, key: impl Borrow<K>, ) -> bool
Mark a query as stale.
Any active resources will refetch in the background, replacing them when ready.
Sourcepub fn invalidate_queries<K, V, KRef, M>(
&self,
query_scope: impl QueryScopeLocalTrait<K, V, M>,
keys: impl IntoIterator<Item = KRef>,
) -> Vec<KRef>
pub fn invalidate_queries<K, V, KRef, M>( &self, query_scope: impl QueryScopeLocalTrait<K, V, M>, keys: impl IntoIterator<Item = KRef>, ) -> Vec<KRef>
Mark multiple queries of a specific type as stale.
Any active resources will refetch in the background, replacing them when ready.
Sourcepub fn invalidate_queries_with_predicate<K, V, M>(
&self,
query_scope: impl QueryScopeLocalTrait<K, V, M>,
should_invalidate: impl Fn(&K) -> bool,
)
pub fn invalidate_queries_with_predicate<K, V, M>( &self, query_scope: impl QueryScopeLocalTrait<K, V, M>, should_invalidate: impl Fn(&K) -> bool, )
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.
Sourcepub fn invalidate_query_scope<K, V, M>(
&self,
query_scope: impl QueryScopeLocalTrait<K, V, M>,
)
pub fn invalidate_query_scope<K, V, M>( &self, query_scope: impl QueryScopeLocalTrait<K, V, M>, )
Mark all queries of a specific type as stale.
Any active resources will refetch in the background, replacing them when ready.
Sourcepub fn invalidate_all_queries(&self)
pub fn invalidate_all_queries(&self)
Mark all queries as stale.
Any active resources will refetch in the background, replacing them when ready.
Sourcepub fn clear(&self)
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>
impl<Codec: 'static> Clone for QueryClient<Codec>
Source§impl<Codec> Debug for QueryClient<Codec>
impl<Codec> Debug for QueryClient<Codec>
Source§impl Default for QueryClient<RkyvCodec>
impl Default for QueryClient<RkyvCodec>
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> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out
indicating that a T
is niched.