Struct leptos::MultiAction
source · pub struct MultiAction<I, O>(_)
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(cx, |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(cx, |input: &String| {
let input = input.clone();
async move { todo!() }
});
// if there are no arguments, use the unit type `()`
let action2 = create_multi_action(cx, |input: &()| async { todo!() });
// if there are multiple arguments, use a tuple
let action3 =
create_multi_action(cx, |input: &(usize, String)| async { todo!() });
Implementations§
source§impl<I, O> MultiAction<I, O>where
I: 'static,
O: 'static,
impl<I, O> MultiAction<I, O>where I: 'static, O: 'static,
sourcepub fn dispatch(&self, input: I)
pub fn dispatch(&self, input: I)
Calls the async
function with a reference to the input type as its argument.
sourcepub fn submissions(&self) -> ReadSignal<Vec<Submission<I, O>, Global>>
pub fn submissions(&self) -> ReadSignal<Vec<Submission<I, O>, Global>>
The set of all submissions to this multi-action.
sourcepub fn url(&self) -> Option<String>
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
.
sourcepub fn using_server_fn<T>(self) -> MultiAction<I, O>where
T: ServerFn,
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,
impl<I, O> Clone for MultiAction<I, O>where I: 'static, O: 'static,
source§fn clone(&self) -> MultiAction<I, O>
fn clone(&self) -> MultiAction<I, O>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more