pub struct Observer<R> { /* private fields */ }client only.Expand description
Observes a resource and triggers re-renders only on status changes.
In v2, the observer only calls cx.notify() when the status actually
changes, preventing excessive re-renders from intermediate state updates
like retry count increments.
This is a single generic implementation shared by every resource kind
(audit L8). Use the QueryObserver / InfiniteQueryObserver /
MutationObserver type aliases for the concrete kinds.
This is also the fix for audit findings #1/#11: the raw cx.observe in
use_mutation unconditionally called cx.notify() on every entity
mutation, causing 2-3 re-renders per retry attempt. By tracking the last
status and only notifying on change, increment_retry() / prepare_retry()
calls (which don’t change status — it stays Loading) no longer trigger
re-renders.
Implementations§
Source§impl<R: ObservableResource + 'static> Observer<R>
impl<R: ObservableResource + 'static> Observer<R>
Sourcepub fn with_config(self, config: ObserverConfig) -> Self
pub fn with_config(self, config: ObserverConfig) -> Self
Set the observer configuration.
Sourcepub fn observe<W: 'static>(
&self,
cx: &mut Context<'_, W>,
) -> Option<Subscription>
pub fn observe<W: 'static>( &self, cx: &mut Context<'_, W>, ) -> Option<Subscription>
Start observing the entity. Returns None if the entity was already dropped.
v2 fix: Returns Option<Subscription> instead of panicking.
Audit #71: takes &self (was &mut self) — the body only reads the
weak entity handle and the Copy config flag, so no interior mutation
is required. &mut callers coerce to & with no ripple.
Auto Trait Implementations§
impl<R> !RefUnwindSafe for Observer<R>
impl<R> !UnwindSafe for Observer<R>
impl<R> Freeze for Observer<R>where
WeakEntity<R>: Freeze,
impl<R> Send for Observer<R>where
WeakEntity<R>: Send,
impl<R> Sync for Observer<R>where
WeakEntity<R>: Sync,
impl<R> Unpin for Observer<R>where
WeakEntity<R>: Unpin,
impl<R> UnsafeUnpin for Observer<R>where
WeakEntity<R>: UnsafeUnpin,
Blanket Implementations§
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
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 more