Struct leptos::Trigger

source ·
pub struct Trigger { /* private fields */ }
Expand description

Reactive Trigger, notifies reactive code to rerun.

See create_trigger for more.

Implementations§

source§

impl Trigger

source

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");
source

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.

source

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.

source

pub fn track(&self)

Subscribes the running effect to this trigger.

§Panics

Panics if there is no current reactive runtime, or if the trigger has been disposed.

source

pub fn try_track(&self) -> bool

Attempts to subscribe the running effect to this trigger, returning false if there is no current reactive runtime.

Trait Implementations§

source§

impl Clone for Trigger

source§

fn clone(&self) -> Trigger

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Trigger

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl Default for Trigger

source§

fn default() -> Trigger

Returns the “default value” for a type. Read more
source§

impl PartialEq for Trigger

source§

fn eq(&self, other: &Trigger) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl SignalGet for Trigger

§

type Value = ()

The value held by the signal.
source§

fn get(&self)

Clones and returns the current value of the signal, and subscribes the running effect to this signal. Read more
source§

fn try_get(&self) -> Option<()>

Clones and returns the signal value, returning Some if the signal is still alive, and None otherwise.
source§

impl SignalSet for Trigger

§

type Value = ()

The value held by the signal.
source§

fn set(&self, _: ())

Sets the signal’s value and notifies subscribers. Read more
source§

fn try_set(&self, _: ()) -> Option<()>

Sets the signal’s value and notifies subscribers. Returns None if the signal is still valid, [Some(T)] otherwise. Read more
source§

impl SignalUpdate for Trigger

§

type Value = ()

The value held by the signal.
source§

fn update(&self, f: impl FnOnce(&mut ()))

Applies a function to the current value to mutate it in place and notifies subscribers that the signal has changed. Read more
source§

fn try_update<O>(&self, f: impl FnOnce(&mut ()) -> O) -> Option<O>

Applies a function to the current value to mutate it in place and notifies subscribers that the signal has changed. Returns [Some(O)] if the signal is still valid, None otherwise. Read more
source§

impl Copy for Trigger

source§

impl Eq for Trigger

source§

impl StructuralPartialEq for Trigger

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<El> ElementDescriptorBounds for El
where El: Debug,