leptos::server

Struct ServerAction

Source
pub struct ServerAction<S>
where S: ServerFn + 'static, <S as ServerFn>::Output: 'static,
{ /* private fields */ }
Expand description

An Action that can be used to call a server function.

Implementations§

Source§

impl<S> ServerAction<S>
where S: ServerFn + Send + Sync + Clone + 'static, <S as ServerFn>::Output: Send + Sync + 'static, <S as ServerFn>::Error: Send + Sync + 'static,

Source

pub fn new() -> ServerAction<S>

Creates a new Action that will call the server function S when dispatched.

Methods from Deref<Target = Action<S, Result<<S as ServerFn>::Output, ServerFnError<<S as ServerFn>::Error>>>>§

Source

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.

Source

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);
Source

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);
Source

pub fn input(&self) -> RwSignal<Option<I>>
where I: Send + Sync,

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 = ArcAction::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);
Source

pub fn input_local(&self) -> RwSignal<Option<I>, LocalStorage>

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.

Source

pub fn value(&self) -> RwSignal<Option<O>>
where O: Send + Sync,

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));
Source

pub fn value_local(&self) -> RwSignal<Option<O>, LocalStorage>
where O: Send + Sync,

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.

Source

pub fn dispatch(&self, input: I) -> ActionAbortHandle

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

Source

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>
where S: ServerFn + 'static, <S as ServerFn>::Output: 'static,

Source§

fn clone(&self) -> ServerAction<S>

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<S> Default for ServerAction<S>
where S: ServerFn + Clone + Send + Sync + 'static, <S as ServerFn>::Output: Send + Sync + 'static, <S as ServerFn>::Error: Send + Sync + 'static,

Source§

fn default() -> ServerAction<S>

Returns the “default value” for a type. Read more
Source§

impl<S> DefinedAt for ServerAction<S>
where S: ServerFn + 'static, <S as ServerFn>::Output: 'static,

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<S> Deref for ServerAction<S>
where S: ServerFn + Clone + Send + Sync + 'static, <S as ServerFn>::Output: Send + Sync + 'static, <S as ServerFn>::Error: Send + Sync + 'static,

Source§

type Target = Action<S, Result<<S as ServerFn>::Output, ServerFnError<<S as ServerFn>::Error>>>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &<ServerAction<S> as Deref>::Target

Dereferences the value.
Source§

impl<S> From<ServerAction<S>> for Action<S, Result<<S as ServerFn>::Output, ServerFnError<<S as ServerFn>::Error>>>
where S: ServerFn + 'static, <S as ServerFn>::Output: 'static,

Source§

fn from( value: ServerAction<S>, ) -> Action<S, Result<<S as ServerFn>::Output, ServerFnError<<S as ServerFn>::Error>>>

Converts to this type from the input type.
Source§

impl<S> Copy for ServerAction<S>
where S: ServerFn + 'static, <S as ServerFn>::Output: 'static,

Auto Trait Implementations§

§

impl<S> Freeze for ServerAction<S>

§

impl<S> RefUnwindSafe for ServerAction<S>

§

impl<S> Send for ServerAction<S>

§

impl<S> Sync for ServerAction<S>

§

impl<S> Unpin for ServerAction<S>

§

impl<S> UnwindSafe for ServerAction<S>

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, dst: *mut u8)

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

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T