pub struct QueryScopeLocal<K, V> { /* private fields */ }
Expand description
A
non-threadsafe
wrapper for a query function. This can be used to add specific QueryOptions
to only apply to one query scope.
These QueryOptions
will be combined with the global QueryOptions
set on the crate::QueryClient
, with the local options taking precedence.
If you don’t need to set specific options, you can use functions with the crate::QueryClient
directly.
Implementations§
Source§impl<K, V> QueryScopeLocal<K, V>
impl<K, V> QueryScopeLocal<K, V>
Sourcepub fn new<M>(query_scope: impl QueryScopeLocalTrait<K, V, M> + 'static) -> Selfwhere
K: 'static,
V: 'static,
pub fn new<M>(query_scope: impl QueryScopeLocalTrait<K, V, M> + 'static) -> Selfwhere
K: 'static,
V: 'static,
Create a new
QueryScopeLocal
.
If the query fn does not have a key argument, K=()
Sourcepub fn with_options(self, options: QueryOptions) -> Self
pub fn with_options(self, options: QueryOptions) -> Self
Set specific QueryOptions
to only apply to this query scope.
These QueryOptions
will be combined with the global QueryOptions
set on the crate::QueryClient
, with the local options taking precedence.
Sourcepub fn with_invalidation_link<S, I>(
self,
invalidation_hierarchy_fn: impl Fn(&K) -> I + Send + Sync + 'static,
) -> Self
pub fn with_invalidation_link<S, I>( self, invalidation_hierarchy_fn: impl Fn(&K) -> I + Send + Sync + 'static, ) -> Self
Different query types are sometimes linked to the same source, e.g. you may want an invalidation of list_blogposts()
to always automatically invalidate get_blogpost(id)
.
QueryScope::with_invalidation_link
can be used to this effect, given a query key &K
, you provide a Vec<String>
that’s used as a hierarchy key (HK) for that query. When a query is invalidated, any query’s HK that’s prefixed by this HK will also be invalidated automatically. E.g. A query with HK ["users"]
will also auto invalidate another query with ["users", "1"]
, but not the other way around. 2 queries with an identicial HK of ["users"]
will auto invalidate each other.
use std::time::Duration;
use leptos_fetch::{QueryClient, QueryScope, QueryOptions};
use leptos::prelude::*;
#[derive(Debug, Clone)]
struct User;
fn list_users_query() -> QueryScope<(), Vec<User>> {
QueryScope::new(async || vec![])
.with_invalidation_link(
|_key| ["users"]
)
}
fn get_user_query() -> QueryScope<i32, User> {
QueryScope::new(async move |user_id: i32| User)
.with_invalidation_link(
|user_id| ["users".to_string(), user_id.to_string()]
)
}
let client = QueryClient::new();
// This invalidates only user "2", because ["users", "2"] is not a prefix of ["users"],
// list_users_query is NOT invalidated.
client.invalidate_query(get_user_query(), &2);
// This invalidates both queries, because ["users"] is a prefix of ["users", "$x"]
client.invalidate_query(list_users_query(), &());
Sourcepub fn with_title(self, title: impl Into<String>) -> Self
Available on crate features devtools
or devtools-always
only.
pub fn with_title(self, title: impl Into<String>) -> Self
devtools
or devtools-always
only.Set a custom query scope/type title that will show in devtools.
Trait Implementations§
Source§impl<K: Clone, V: Clone> Clone for QueryScopeLocal<K, V>
impl<K: Clone, V: Clone> Clone for QueryScopeLocal<K, V>
Source§fn clone(&self) -> QueryScopeLocal<K, V>
fn clone(&self) -> QueryScopeLocal<K, V>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreAuto Trait Implementations§
impl<K, V> Freeze for QueryScopeLocal<K, V>
impl<K, V> !RefUnwindSafe for QueryScopeLocal<K, V>
impl<K, V> !Send for QueryScopeLocal<K, V>
impl<K, V> !Sync for QueryScopeLocal<K, V>
impl<K, V> Unpin for QueryScopeLocal<K, V>
impl<K, V> !UnwindSafe for QueryScopeLocal<K, V>
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.