pub struct Owner { /* private fields */ }Expand description
The owner of the reactive values and effects created while it is current.
Owners form a tree. Owner::new attaches to the current owner when there
is one, Owner::child attaches to an owner directly, and Owner::set
and Owner::with make one current, which is where new values and effects
are registered. Owner::cleanup stops the owner’s effects and disposes
its values, children first; dropping the last handle to an owner does the
same, so nothing has to be cleaned up by hand.
Context values are provided on an owner with provide_context and read
by the owner and its descendants with use_context.
Implementations§
Source§impl Owner
impl Owner
Sourcepub fn new() -> Owner
pub fn new() -> Owner
Creates an owner under the current owner, when there is one.
With no current owner the new owner starts a new root scope, which carries its own wake callback.
Sourcepub fn child(&self) -> Owner
pub fn child(&self) -> Owner
Creates an owner under this one.
The child inherits this owner’s root scope, so its effects wake the same redraw requests.
Sourcepub fn set(&self)
pub fn set(&self)
Makes this owner current until another one is set or a with block
restores the previous one.
Sourcepub fn with<T>(&self, fun: impl FnOnce() -> T) -> T
pub fn with<T>(&self, fun: impl FnOnce() -> T) -> T
Runs fun with this owner current, restoring the previous one after.
Sourcepub fn cleanup(&self)
pub fn cleanup(&self)
Stops the owner’s effects and disposes the values created under it,
children first, then runs the cleanup functions that
Owner::on_cleanup registered.
Running it twice does nothing. Dropping the last handle to the owner runs it too.
Sourcepub fn set_wake_callback(&self, callback: impl Fn() + 'static)
pub fn set_wake_callback(&self, callback: impl Fn() + 'static)
Sets the callback that a wake in this owner’s tree runs to request a redraw.
Every effect created under this owner reports its wake here, so two
owners on one thread each get their own redraw requests. See
set_wake_callback for when the callback runs.
Sourcepub fn on_cleanup(fun: impl FnOnce() + 'static)
pub fn on_cleanup(fun: impl FnOnce() + 'static)
Registers fun to run when the current owner is cleaned up.
With no current owner, fun is dropped.