Struct leptos::MultiAction

source ·
pub struct MultiAction<I, O>(/* private fields */)
where
    I: 'static,
    O: 'static;
Expand description

An action that synchronizes multiple imperative async calls to the reactive system, tracking the progress of each one.

Where an Action fires a single call, a MultiAction allows you to keep track of multiple in-flight actions.

If you’re trying to load data by running an async function reactively, you probably want to use a Resource instead. If you’re trying to occasionally run an async function in response to something like a user adding a task to a todo list, you’re in the right place.

async fn send_new_todo_to_api(task: String) -> usize {
  // do something...
  // return a task id
  42
}
let add_todo = create_multi_action(|task: &String| {
  // `task` is given as `&String` because its value is available in `input`
  send_new_todo_to_api(task.clone())
});

add_todo.dispatch("Buy milk".to_string());
add_todo.dispatch("???".to_string());
add_todo.dispatch("Profit!!!".to_string());

The input to the async function should always be a single value, but it can be of any type. The argument is always passed by reference to the function, because it is stored in Submission::input as well.

// if there's a single argument, just use that
let action1 = create_multi_action(|input: &String| {
    let input = input.clone();
    async move { todo!() }
});

// if there are no arguments, use the unit type `()`
let action2 = create_multi_action(|input: &()| async { todo!() });

// if there are multiple arguments, use a tuple
let action3 =
    create_multi_action(|input: &(usize, String)| async { todo!() });

Implementations§

source§

impl<I, O> MultiAction<I, O>
where I: 'static, O: 'static,

source

pub fn dispatch(&self, input: I)

Calls the async function with a reference to the input type as its argument.

source

pub fn submissions(&self) -> ReadSignal<Vec<Submission<I, O>>>

The set of all submissions to this multi-action.

source

pub fn url(&self) -> Option<String>

The URL associated with the action (typically as part of a server function.) This enables integration with the MultiActionForm component in leptos_router.

source

pub fn version(&self) -> RwSignal<usize>

How many times an action has successfully resolved.

source

pub fn using_server_fn<T>(self) -> MultiAction<I, O>
where T: ServerFn,

Associates the URL of the given server function with this action. This enables integration with the MultiActionForm component in leptos_router.

Trait Implementations§

source§

impl<I, O> Clone for MultiAction<I, O>
where I: 'static, O: 'static,

source§

fn clone(&self) -> MultiAction<I, O>

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<I, O> Copy for MultiAction<I, O>
where I: 'static, O: 'static,

Auto Trait Implementations§

§

impl<I, O> Freeze for MultiAction<I, O>

§

impl<I, O> !RefUnwindSafe for MultiAction<I, O>

§

impl<I, O> !Send for MultiAction<I, O>

§

impl<I, O> !Sync for MultiAction<I, O>

§

impl<I, O> Unpin for MultiAction<I, O>
where I: Unpin, O: Unpin,

§

impl<I, O> !UnwindSafe for MultiAction<I, O>

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