pub struct Owner { /* private fields */ }Expand description
A reactive owner, which manages
- the cancellation of
Effects, - providing and accessing environment data via
provide_contextanduse_context, - running cleanup functions defined via
Owner::on_cleanup, and - an arena storage system to provide
Copyhandles viaArenaItem, which is what allows types likeRwSignal,Memo, and so on to beCopy.
Every effect and computed reactive value has an associated Owner. While it is running, this
is marked as the current Owner. Whenever it re-runs, this Owner is cleared by calling
Owner::with_cleanup. This runs cleanup functions, cancels any Effects created during the
last run, drops signals stored in the arena, and so on, because those effects and signals will
be re-created as needed during the next run.
When the owner is ultimately dropped, it will clean up its owned resources in the same way.
The “current owner” is set on the thread-local basis: whenever one of these reactive nodes is
running, it will set the current owner on its thread with Owner::with or Owner::set,
allowing other reactive nodes implicitly to access the fact that it is currently the owner.
For a longer discussion of the ownership model, see here.
Implementations§
Source§impl Owner
impl Owner
Sourcepub fn use_context_bidirectional<T>(&self) -> Option<T>where
T: Clone + 'static,
pub fn use_context_bidirectional<T>(&self) -> Option<T>where
T: Clone + 'static,
Searches for items stored in context in either direction, either among parents or among descendants.
Source§impl Owner
impl Owner
Sourcepub fn debug_id(&self) -> usize
pub fn debug_id(&self) -> usize
Returns a unique identifier for this owner, which can be used to identify it for debugging purposes.
Intended for debugging only; this is not guaranteed to be stable between runs.
Sourcepub fn ancestry(&self) -> Vec<usize>
pub fn ancestry(&self) -> Vec<usize>
Returns the list of parents, grandparents, and ancestors, with values corresponding to
Owner::debug_id for each.
Intended for debugging only; this is not guaranteed to be stable between runs.
Sourcepub fn new() -> Owner
pub fn new() -> Owner
Creates a new Owner and registers it as a child of the current Owner, if there is one.
Sourcepub fn new_root(
shared_context: Option<Arc<dyn SharedContext + Sync + Send>>,
) -> Owner
pub fn new_root( shared_context: Option<Arc<dyn SharedContext + Sync + Send>>, ) -> Owner
Creates a new “root” context with the given SharedContext, which allows sharing data
between the server and client.
Only one SharedContext needs to be created per request, and will be automatically shared
by any other Owners created under this one.
Sourcepub fn parent(&self) -> Option<Owner>
pub fn parent(&self) -> Option<Owner>
Returns the parent of this Owner, if any.
None when:
- This is a root owner
- The parent has been dropped
Sourcepub fn child(&self) -> Owner
pub fn child(&self) -> Owner
Creates a new Owner that is the child of the current Owner, if any.
Sourcepub fn with<T>(&self, fun: impl FnOnce() -> T) -> T
pub fn with<T>(&self, fun: impl FnOnce() -> T) -> T
Runs the given function with this as the current Owner.
Sourcepub fn with_cleanup<T>(&self, fun: impl FnOnce() -> T) -> T
pub fn with_cleanup<T>(&self, fun: impl FnOnce() -> T) -> T
Cleans up this owner, the given function with this as the current Owner.
Sourcepub fn cleanup(&self)
pub fn cleanup(&self)
Cleans up this owner in the following order:
- Runs
cleanupon all children, - Runs all cleanup functions registered with
Owner::on_cleanup, - Drops the values of any arena-allocated
ArenaItems.
Sourcepub fn on_cleanup(fun: impl FnOnce() + Send + Sync + 'static)
pub fn on_cleanup(fun: impl FnOnce() + Send + Sync + 'static)
Registers a function to be run the next time the current owner is cleaned up.
Because the ownership model is associated with reactive nodes, each “decision point” in an
application tends to have a separate Owner: as a result, these cleanup functions often
fill the same need as an “on unmount” function in other UI approaches, etc.
Returns the SharedContext associated with this owner, if any.
Returns the current SharedContext, if any.
Sourcepub fn with_hydration<T>(fun: impl FnOnce() -> T + 'static) -> T
pub fn with_hydration<T>(fun: impl FnOnce() -> T + 'static) -> T
Runs the given function, after indicating that the current SharedContext should be
prepared to handle any data created in the function.
Sourcepub fn with_no_hydration<T>(fun: impl FnOnce() -> T + 'static) -> T
pub fn with_no_hydration<T>(fun: impl FnOnce() -> T + 'static) -> T
Runs the given function, after indicating that the current SharedContext should /// not handle data created in this function.
Sourcepub fn pause(&self)
pub fn pause(&self)
Pauses the execution of side effects for this owner, and any of its descendants.
If this owner is the owner for an Effect or RenderEffect, this effect will not run until Owner::resume is called. All children of this effects are also paused.
Any notifications will be ignored; effects that are notified will paused will not run when resumed, until they are notified again by a source after being resumed.
Sourcepub fn paused(&self) -> bool
pub fn paused(&self) -> bool
Whether this owner has been paused by Owner::pause.
Sourcepub fn resume(&self)
pub fn resume(&self)
Resumes side effects that have been paused by Owner::pause.
All children will also be resumed.
This will not cause side effects that were notified while paused to run, until they are notified again by a source after being resumed.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Owner
impl !RefUnwindSafe for Owner
impl Send for Owner
impl Sync for Owner
impl Unpin for Owner
impl !UnwindSafe for Owner
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
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 more