pub struct ServerAction<S>{ /* private fields */ }Expand description
An Action that can be used to call a server function.
Implementations§
Methods from Deref<Target = Action<S, Result<S::Output, S::Error>>>§
Sourcepub fn clear(&self)
pub fn clear(&self)
Clears the value of the action, setting its current value to None.
This has no other effect: i.e., it will not cancel in-flight actions, set the input, etc.
Sourcepub fn version(&self) -> RwSignal<usize>
pub fn version(&self) -> RwSignal<usize>
The number of times the action has successfully completed.
let act = Action::new(|n: &u8| {
let n = n.to_owned();
async move { n * 2 }
});
let version = act.version();
act.dispatch(3);
assert_eq!(version.get(), 0);
// after it resolves
assert_eq!(version.get(), 1);Sourcepub fn pending(&self) -> Memo<bool>
pub fn pending(&self) -> Memo<bool>
Whether the action has been dispatched and is currently waiting to resolve.
let act = Action::new(|n: &u8| {
let n = n.to_owned();
async move { n * 2 }
});
let pending = act.pending();
assert_eq!(pending.get(), false);
act.dispatch(3);
assert_eq!(pending.get(), true);
// after it resolves
assert_eq!(pending.get(), false);Sourcepub fn input(&self) -> MappedSignal<Option<I>>
pub fn input(&self) -> MappedSignal<Option<I>>
The current argument that was dispatched to the async function. This value will
be Some while we are waiting for it to resolve, and None after it has resolved.
let act = Action::new(|n: &u8| {
let n = n.to_owned();
async move { n * 2 }
});
let input = act.input();
assert_eq!(input.get(), None);
act.dispatch(3);
assert_eq!(input.get(), Some(3));
// after it resolves
assert_eq!(input.get(), None);Sourcepub fn input_local(&self) -> MappedSignal<Option<I>>
👎Deprecated: You can now use .input() for any value, whether it’s thread-safe or not.
pub fn input_local(&self) -> MappedSignal<Option<I>>
The current argument that was dispatched to the async function. This value will
be Some while we are waiting for it to resolve, and None after it has resolved.
Returns a thread-local signal using [LocalStorage].
Sourcepub fn value(&self) -> MappedSignal<Option<O>>
pub fn value(&self) -> MappedSignal<Option<O>>
The most recent return value of the async function. This will be None before
the action has ever run successfully, and subsequently will always be Some(_),
holding the old value until a new value has been received.
let act = Action::new(|n: &u8| {
let n = n.to_owned();
async move { n * 2 }
});
let value = act.value();
assert_eq!(value.get(), None);
act.dispatch(3);
assert_eq!(value.get(), None);
// after it resolves
assert_eq!(value.get(), Some(6));
// dispatch another value, and it still holds the old value
act.dispatch(3);
assert_eq!(value.get(), Some(6));Sourcepub fn value_local(&self) -> MappedSignal<Option<O>>
👎Deprecated: You can now use .value() for any value, whether it’s thread-safe or not.
pub fn value_local(&self) -> MappedSignal<Option<O>>
The most recent return value of the async function. This will be None before
the action has ever run successfully, and subsequently will always be Some(_),
holding the old value until a new value has been received.
Returns a thread-local signal using [LocalStorage].
Sourcepub fn dispatch(&self, input: I) -> ActionAbortHandle
pub fn dispatch(&self, input: I) -> ActionAbortHandle
Calls the async function with a reference to the input type as its argument.
Sourcepub fn dispatch_local(&self, input: I) -> ActionAbortHandle
pub fn dispatch_local(&self, input: I) -> ActionAbortHandle
Calls the async function with a reference to the input type as its argument.
Trait Implementations§
Source§impl<S> Clone for ServerAction<S>
impl<S> Clone for ServerAction<S>
Source§impl<S> Default for ServerAction<S>
impl<S> Default for ServerAction<S>
Source§impl<S> DefinedAt for ServerAction<S>
impl<S> DefinedAt for ServerAction<S>
Source§fn defined_at(&self) -> Option<&'static Location<'static>>
fn defined_at(&self) -> Option<&'static Location<'static>>
None in
release mode.