pub struct Trigger { /* private fields */ }
Expand description
Reactive Trigger, notifies reactive code to rerun.
See create_trigger
for more.
Implementations§
source§impl Trigger
impl Trigger
sourcepub fn new() -> Trigger
pub fn new() -> Trigger
Creates a Trigger
, a kind of reactive primitive.
A trigger is a data-less signal with the sole purpose of notifying other reactive code of a change. This can be useful for when using external data not stored in signals, for example.
This is identical to create_trigger
.
use std::{cell::RefCell, fmt::Write, rc::Rc};
let external_data = Rc::new(RefCell::new(1));
let output = Rc::new(RefCell::new(String::new()));
let rerun_on_data = Trigger::new();
let o = output.clone();
let e = external_data.clone();
create_effect(move |_| {
// can be `rerun_on_data()` on nightly
rerun_on_data.track();
write!(o.borrow_mut(), "{}", *e.borrow());
*e.borrow_mut() += 1;
});
assert_eq!(*output.borrow(), "1");
rerun_on_data.notify(); // reruns the above effect
assert_eq!(*output.borrow(), "12");
sourcepub fn notify(&self)
pub fn notify(&self)
Notifies any reactive code where this trigger is tracked to rerun.
§Panics
Panics if there is no current reactive runtime, or if the trigger has been disposed.
sourcepub fn try_notify(&self) -> bool
pub fn try_notify(&self) -> bool
Attempts to notify any reactive code where this trigger is tracked to rerun.
Returns false
if there is no current reactive runtime.
Trait Implementations§
source§impl PartialEq for Trigger
impl PartialEq for Trigger
source§impl SignalGet for Trigger
impl SignalGet for Trigger
source§impl SignalUpdate for Trigger
impl SignalUpdate for Trigger
impl Copy for Trigger
impl Eq for Trigger
impl StructuralPartialEq for Trigger
Auto Trait Implementations§
impl Freeze for Trigger
impl RefUnwindSafe for Trigger
impl Send for Trigger
impl Sync for Trigger
impl Unpin for Trigger
impl UnwindSafe for Trigger
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
Mutably borrows from an owned value. Read more
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.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>
Converts
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>
Converts
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