Skip to main content

ImmediateEffect

Struct ImmediateEffect 

Source
pub struct ImmediateEffect { /* private fields */ }
Expand description

Effects run a certain chunk of code whenever the signals they depend on change.

The effect runs on creation and again as soon as any tracked signal changes.

NOTE: you probably want use Effect instead. This is for the few cases where it’s important to execute effects immediately and in order.

ImmediateEffects stop running when dropped.

NOTE: since effects are executed immediately, they might recurse. Under recursion or parallelism only the last run to start is tracked.

§Example

let a = RwSignal::new(0);
let b = RwSignal::new(0);

// ✅ use effects to interact between reactive state and the outside world
let _drop_guard = ImmediateEffect::new(move || {
  // on the next “tick” prints "Value: 0" and subscribes to `a`
  println!("Value: {}", a.get());
});

// The effect runs immediately and subscribes to `a`, in the process it prints "Value: 0"
a.set(1);
// ✅ because it's subscribed to `a`, the effect reruns and prints "Value: 1"

§Notes

  1. Scheduling: Effects run immediately, as soon as any tracked signal changes.
  2. By default, effects do not run unless the effects feature is enabled. If you are using this with a web framework, this generally means that effects do not run on the server. and you can call browser-specific APIs within the effect function without causing issues. If you need an effect to run on the server, use ImmediateEffect::new_isomorphic.

Implementations§

Source§

impl ImmediateEffect

Source

pub fn new(fun: impl Fn() + Send + Sync + 'static) -> ImmediateEffect

Creates a new effect which runs immediately, then again as soon as any tracked signal changes. (Unless batch is used.)

NOTE: this requires a Fn function because it might recurse. Use Self::new_mut to pass a FnMut function, it’ll panic on recursion.

Source

pub fn new_mut(fun: impl FnMut() + Send + Sync + 'static) -> ImmediateEffect

Creates a new effect which runs immediately, then again as soon as any tracked signal changes. (Unless batch is used.)

§Panics

Panics on recursion or if triggered in parallel. Also see Self::new

Source

pub fn new_scoped(fun: impl Fn() + Send + Sync + 'static)

Creates a new effect which runs immediately, then again as soon as any tracked signal changes. (Unless batch is used.)

NOTE: this requires a Fn function because it might recurse. Use Self::new_mut_scoped to pass a FnMut function, it’ll panic on recursion. NOTE: this effect is automatically cleaned up when the current owner is cleared or disposed.

Source

pub fn new_mut_scoped(fun: impl FnMut() + Send + Sync + 'static)

Creates a new effect which runs immediately, then again as soon as any tracked signal changes. (Unless batch is used.)

NOTE: this effect is automatically cleaned up when the current owner is cleared or disposed.

§Panics

Panics on recursion or if triggered in parallel. Also see Self::new_scoped

Source

pub fn new_isomorphic(fun: impl Fn() + Send + Sync + 'static) -> ImmediateEffect

Creates a new effect which runs immediately, then again as soon as any tracked signal changes.

This will run whether the effects feature is enabled or not.

Trait Implementations§

Source§

impl Clone for ImmediateEffect

Source§

fn clone(&self) -> ImmediateEffect

Returns a duplicate 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 ImmediateEffect

Source§

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

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

impl DefinedAt for ImmediateEffect

Source§

fn defined_at(&self) -> Option<&'static Location<'static>>

Returns the location at which the signal was defined. This is usually simply None in release mode.
Source§

impl Dispose for ImmediateEffect

Source§

fn dispose(self)

Disposes of the signal. This: Read more
Source§

impl ToAnySubscriber for ImmediateEffect

Source§

fn to_any_subscriber(&self) -> AnySubscriber

Converts this type to its type-erased equivalent.

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<E, T, Request, Encoding> FromReq<Patch<Encoding>, Request, E> for T
where Request: Req<E> + Send + 'static, Encoding: Decodes<T>, E: FromServerFnError,

Source§

async fn from_req(req: Request) -> Result<T, E>

Attempts to deserialize the arguments from a request.
Source§

impl<E, T, Request, Encoding> FromReq<Post<Encoding>, Request, E> for T
where Request: Req<E> + Send + 'static, Encoding: Decodes<T>, E: FromServerFnError,

Source§

async fn from_req(req: Request) -> Result<T, E>

Attempts to deserialize the arguments from a request.
Source§

impl<E, T, Request, Encoding> FromReq<Put<Encoding>, Request, E> for T
where Request: Req<E> + Send + 'static, Encoding: Decodes<T>, E: FromServerFnError,

Source§

async fn from_req(req: Request) -> Result<T, E>

Attempts to deserialize the arguments from a request.
Source§

impl<E, Encoding, Response, T> FromRes<Patch<Encoding>, Response, E> for T
where Response: ClientRes<E> + Send, Encoding: Decodes<T>, E: FromServerFnError,

Source§

async fn from_res(res: Response) -> Result<T, E>

Attempts to deserialize the outputs from a response.
Source§

impl<E, Encoding, Response, T> FromRes<Post<Encoding>, Response, E> for T
where Response: ClientRes<E> + Send, Encoding: Decodes<T>, E: FromServerFnError,

Source§

async fn from_res(res: Response) -> Result<T, E>

Attempts to deserialize the outputs from a response.
Source§

impl<E, Encoding, Response, T> FromRes<Put<Encoding>, Response, E> for T
where Response: ClientRes<E> + Send, Encoding: Decodes<T>, E: FromServerFnError,

Source§

async fn from_res(res: Response) -> Result<T, E>

Attempts to deserialize the outputs from a response.
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<E, T, Encoding, Request> IntoReq<Patch<Encoding>, Request, E> for T
where Request: ClientReq<E>, Encoding: Encodes<T>, E: FromServerFnError,

Source§

fn into_req(self, path: &str, accepts: &str) -> Result<Request, E>

Attempts to serialize the arguments into an HTTP request.
Source§

impl<E, T, Encoding, Request> IntoReq<Post<Encoding>, Request, E> for T
where Request: ClientReq<E>, Encoding: Encodes<T>, E: FromServerFnError,

Source§

fn into_req(self, path: &str, accepts: &str) -> Result<Request, E>

Attempts to serialize the arguments into an HTTP request.
Source§

impl<E, T, Encoding, Request> IntoReq<Put<Encoding>, Request, E> for T
where Request: ClientReq<E>, Encoding: Encodes<T>, E: FromServerFnError,

Source§

fn into_req(self, path: &str, accepts: &str) -> Result<Request, E>

Attempts to serialize the arguments into an HTTP request.
Source§

impl<E, Response, Encoding, T> IntoRes<Patch<Encoding>, Response, E> for T
where Response: TryRes<E>, Encoding: Encodes<T>, E: FromServerFnError + Send, T: Send,

Source§

async fn into_res(self) -> Result<Response, E>

Attempts to serialize the output into an HTTP response.
Source§

impl<E, Response, Encoding, T> IntoRes<Post<Encoding>, Response, E> for T
where Response: TryRes<E>, Encoding: Encodes<T>, E: FromServerFnError + Send, T: Send,

Source§

async fn into_res(self) -> Result<Response, E>

Attempts to serialize the output into an HTTP response.
Source§

impl<E, Response, Encoding, T> IntoRes<Put<Encoding>, Response, E> for T
where Response: TryRes<E>, Encoding: Encodes<T>, E: FromServerFnError + Send, T: Send,

Source§

async fn into_res(self) -> Result<Response, E>

Attempts to serialize the output into an HTTP response.
Source§

impl<T> SerializableKey for T

Source§

fn ser_key(&self) -> String

Serializes the key to a unique string. Read more
Source§

impl<T> StorageAccess<T> for T

Source§

fn as_borrowed(&self) -> &T

Borrows the value.
Source§

fn into_taken(self) -> T

Takes the value.
Source§

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

Source§

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>,

Source§

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>,

Source§

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.