pub struct Scope<COMP: Component> { /* private fields */ }
Expand description
A context which allows sending messages to a component.
Implementations§
Source§impl<COMP: Component> Scope<COMP>
impl<COMP: Component> Scope<COMP>
Sourcepub fn get_parent(&self) -> Option<&AnyScope>
pub fn get_parent(&self) -> Option<&AnyScope>
Returns the parent scope
Sourcepub fn get_component(&self) -> Option<impl Deref<Target = COMP> + '_>
pub fn get_component(&self) -> Option<impl Deref<Target = COMP> + '_>
Returns the linked component if available
Sourcepub fn send_message<T>(&self, msg: T)
pub fn send_message<T>(&self, msg: T)
Send a message to the component.
Please be aware that currently this method synchronously schedules a call to the Component interface.
Sourcepub fn send_message_batch(&self, messages: Vec<COMP::Message>)
pub fn send_message_batch(&self, messages: Vec<COMP::Message>)
Send a batch of messages to the component.
This is useful for reducing re-renders of the components because the messages are handled together and the view function is called only once if needed.
Please be aware that currently this method synchronously schedules calls to the Component interface.
Sourcepub fn callback<F, IN, M>(&self, function: F) -> Callback<IN>
pub fn callback<F, IN, M>(&self, function: F) -> Callback<IN>
Creates a Callback
which will send a message to the linked
component’s update method when invoked.
Please be aware that currently the result of this callback synchronously schedules a call to the Component interface.
Sourcepub fn callback_once<F, IN, M>(&self, function: F) -> Callback<IN>
pub fn callback_once<F, IN, M>(&self, function: F) -> Callback<IN>
Creates a Callback
from an FnOnce
which will send a message
to the linked component’s update method when invoked.
Please be aware that currently the result of this callback will synchronously schedule calls to the Component interface.
Sourcepub fn batch_callback<F, IN, OUT>(&self, function: F) -> Callback<IN>where
F: Fn(IN) -> OUT + 'static,
OUT: SendAsMessage<COMP>,
pub fn batch_callback<F, IN, OUT>(&self, function: F) -> Callback<IN>where
F: Fn(IN) -> OUT + 'static,
OUT: SendAsMessage<COMP>,
Creates a Callback
which will send a batch of messages back
to the linked component’s update method when invoked.
The callback function’s return type is generic to allow for dealing with both
Option
and Vec
nicely. Option
can be used when dealing with a callback that
might not need to send an update.
link.batch_callback(|_| vec![Msg::A, Msg::B]);
link.batch_callback(|_| Some(Msg::A));
Please be aware that currently the results of these callbacks will synchronously schedule calls to the Component interface.
Sourcepub fn batch_callback_once<F, IN, OUT>(&self, function: F) -> Callback<IN>where
F: FnOnce(IN) -> OUT + 'static,
OUT: SendAsMessage<COMP>,
pub fn batch_callback_once<F, IN, OUT>(&self, function: F) -> Callback<IN>where
F: FnOnce(IN) -> OUT + 'static,
OUT: SendAsMessage<COMP>,
Creates a Callback
from an FnOnce
which will send a batch of messages back
to the linked component’s update method when invoked.
The callback function’s return type is generic to allow for dealing with both
Option
and Vec
nicely. Option
can be used when dealing with a callback that
might not need to send an update.
link.batch_callback_once(|_| vec![Msg::A, Msg::B]);
link.batch_callback_once(|_| Some(Msg::A));
Please be aware that currently the results of these callbacks will synchronously schedule calls to the Component interface.
Trait Implementations§
impl<Comp: Component> ImplicitClone for Scope<Comp>
Auto Trait Implementations§
impl<COMP> Freeze for Scope<COMP>
impl<COMP> !RefUnwindSafe for Scope<COMP>
impl<COMP> !Send for Scope<COMP>
impl<COMP> !Sync for Scope<COMP>
impl<COMP> Unpin for Scope<COMP>
impl<COMP> !UnwindSafe for Scope<COMP>
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, V> IntoOptPropValue<V> for Twhere
T: IntoPropValue<Option<V>>,
impl<T, V> IntoOptPropValue<V> for Twhere
T: IntoPropValue<Option<V>>,
Source§fn into_opt_prop_value(self) -> Option<V>
fn into_opt_prop_value(self) -> Option<V>
self
to an optional value of a Properties
struct.Source§impl<T> IntoPropValue<Option<T>> for T
impl<T> IntoPropValue<Option<T>> for T
Source§fn into_prop_value(self) -> Option<T>
fn into_prop_value(self) -> Option<T>
self
to a value of a Properties
struct.Source§impl<T> IntoPropValue<T> for T
impl<T> IntoPropValue<T> for T
Source§fn into_prop_value(self) -> T
fn into_prop_value(self) -> T
self
to a value of a Properties
struct.