pub struct ServerMultiAction<S>{ /* private fields */ }Expand description
A MultiAction that can be used to call a server function.
Implementations§
Source§impl<S> ServerMultiAction<S>
impl<S> ServerMultiAction<S>
Sourcepub fn new() -> ServerMultiAction<S>
pub fn new() -> ServerMultiAction<S>
Creates a new MultiAction which, when dispatched, will call the server function S.
Methods from Deref<Target = MultiAction<S, Result<<S as ServerFn>::Output, ServerFnError<<S as ServerFn>::Error>>>>§
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.
This can be called any number of times: each submission will be dispatched, running
concurrently, and its status can be checked via the
submissions() signal.
async fn send_new_todo_to_api(task: String) -> usize {
// do something...
// return a task id
42
}
let add_todo = MultiAction::new(|task: &String| {
// `task` is given as `&String` because its value is available in `input`
send_new_todo_to_api(task.clone())
});
let submissions = add_todo.submissions();
let pending_submissions = move || {
submissions.with(|subs| subs.iter().filter(|sub| sub.pending().get()).count())
};
add_todo.dispatch("Buy milk".to_string());
assert_eq!(submissions.with(Vec::len), 1);
assert_eq!(pending_submissions(), 1);
add_todo.dispatch("???".to_string());
add_todo.dispatch("Profit!!!".to_string());
assert_eq!(submissions.with(Vec::len), 3);
assert_eq!(pending_submissions(), 3);
// when submissions resolve, they are not removed from the set
// however, their `pending` signal is now `false`, and this can be used to filter them
assert_eq!(submissions.with(Vec::len), 3);
assert_eq!(pending_submissions(), 0);Sourcepub fn dispatch_sync(&self, value: O)
pub fn dispatch_sync(&self, value: O)
Synchronously adds a submission with the given value.
This takes the output value, rather than the input, because it is adding a result, not an input.
This can be useful for use cases like handling errors, where the error can already be known on the client side.
async fn send_new_todo_to_api(task: String) -> usize {
// do something...
// return a task id
42
}
let add_todo = MultiAction::new(|task: &String| {
// `task` is given as `&String` because its value is available in `input`
send_new_todo_to_api(task.clone())
});
let submissions = add_todo.submissions();
let pending_submissions = move || {
submissions.with(|subs| subs.iter().filter(|sub| sub.pending().get()).count())
};
add_todo.dispatch("Buy milk".to_string());
assert_eq!(submissions.with(Vec::len), 1);
assert_eq!(pending_submissions(), 1);
add_todo.dispatch_sync(42);
assert_eq!(submissions.with(Vec::len), 2);
assert_eq!(pending_submissions(), 1);Sourcepub fn submissions(&self) -> ReadSignal<Vec<ArcSubmission<I, O>>>
pub fn submissions(&self) -> ReadSignal<Vec<ArcSubmission<I, O>>>
The set of all submissions to this multi-action.
async fn send_new_todo_to_api(task: String) -> usize {
// do something...
// return a task id
42
}
let add_todo = MultiAction::new(|task: &String| {
// `task` is given as `&String` because its value is available in `input`
send_new_todo_to_api(task.clone())
});
let submissions = add_todo.submissions();
add_todo.dispatch("Buy milk".to_string());
add_todo.dispatch("???".to_string());
add_todo.dispatch("Profit!!!".to_string());
assert_eq!(submissions.with(Vec::len), 3);Sourcepub fn version(&self) -> RwSignal<usize>
pub fn version(&self) -> RwSignal<usize>
How many times an action has successfully resolved.
async fn send_new_todo_to_api(task: String) -> usize {
// do something...
// return a task id
42
}
let add_todo = MultiAction::new(|task: &String| {
// `task` is given as `&String` because its value is available in `input`
send_new_todo_to_api(task.clone())
});
let version = add_todo.version();
add_todo.dispatch("Buy milk".to_string());
add_todo.dispatch("???".to_string());
add_todo.dispatch("Profit!!!".to_string());
assert_eq!(version.get(), 0);
// when they've all resolved
assert_eq!(version.get(), 3);Trait Implementations§
Source§impl<S> Clone for ServerMultiAction<S>
impl<S> Clone for ServerMultiAction<S>
Source§fn clone(&self) -> ServerMultiAction<S>
fn clone(&self) -> ServerMultiAction<S>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl<S> Copy for ServerMultiAction<S>
Source§impl<S> Default for ServerMultiAction<S>
impl<S> Default for ServerMultiAction<S>
Source§fn default() -> ServerMultiAction<S>
fn default() -> ServerMultiAction<S>
Returns the “default value” for a type. Read more
Source§impl<S> DefinedAt for ServerMultiAction<S>
impl<S> DefinedAt for ServerMultiAction<S>
Source§fn defined_at(&self) -> Option<&'static Location<'static>>
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<S> Deref for ServerMultiAction<S>
impl<S> Deref for ServerMultiAction<S>
Source§impl<S> From<ServerMultiAction<S>> for MultiAction<S, Result<<S as ServerFn>::Output, ServerFnError<<S as ServerFn>::Error>>>
impl<S> From<ServerMultiAction<S>> for MultiAction<S, Result<<S as ServerFn>::Output, ServerFnError<<S as ServerFn>::Error>>>
Source§fn from(
value: ServerMultiAction<S>,
) -> MultiAction<S, Result<<S as ServerFn>::Output, ServerFnError<<S as ServerFn>::Error>>>
fn from( value: ServerMultiAction<S>, ) -> MultiAction<S, Result<<S as ServerFn>::Output, ServerFnError<<S as ServerFn>::Error>>>
Converts to this type from the input type.
Auto Trait Implementations§
impl<S> Freeze for ServerMultiAction<S>
impl<S> RefUnwindSafe for ServerMultiAction<S>
impl<S> Send for ServerMultiAction<S>
impl<S> Sync for ServerMultiAction<S>
impl<S> Unpin for ServerMultiAction<S>
impl<S> UnsafeUnpin for ServerMultiAction<S>
impl<S> UnwindSafe for ServerMultiAction<S>
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Converts
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Converts
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Converts
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Converts
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
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 moreSource§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
Source§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
impl<T> SerializableAny for T
Source§impl<T> StorageAccess<T> for T
impl<T> StorageAccess<T> for T
Source§fn as_borrowed(&self) -> &T
fn as_borrowed(&self) -> &T
Borrows the value.
Source§fn into_taken(self) -> T
fn into_taken(self) -> T
Takes the value.
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.