Struct ServerAction

Source
pub struct ServerAction<S>
where S: ServerFn + 'static, S::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::Output: Send + Sync + 'static, S::Error: Send + Sync + 'static,

Source

pub fn new() -> Self

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

Methods from Deref<Target = Action<S, Result<S::Output, S::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) -> 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);
Source

pub fn input_local(&self) -> MappedSignal<Option<I>>

👎Deprecated: You can now use .input() for any value, whether it’s thread-safe or not.

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

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

👎Deprecated: You can now use .value() for any value, whether it’s thread-safe or not.

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::Output: 'static,

Source§

fn clone(&self) -> Self

Returns a duplicate 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::Output: Send + Sync + 'static, S::Error: Send + Sync + 'static,

Source§

fn default() -> Self

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

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

Source§

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

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

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

Source§

fn from(value: ServerAction<S>) -> Self

Converts to this type from the input type.
Source§

impl<S> Copy for ServerAction<S>
where S: ServerFn + 'static, S::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, dest: *mut u8)

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

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<E, T, Request, Encoding> FromReq<Patch<Encoding>, Request, E> for T
where Request: Req<E> + Send + 'static, Encoding: Decodes<T>, E: FromServerFnError,

Source§

async fn from_req(req: Request) -> Result<T, E>

Attempts to deserialize the arguments from a request.
Source§

impl<E, T, Request, Encoding> FromReq<Post<Encoding>, Request, E> for T
where Request: Req<E> + Send + 'static, Encoding: Decodes<T>, E: FromServerFnError,

Source§

async fn from_req(req: Request) -> Result<T, E>

Attempts to deserialize the arguments from a request.
Source§

impl<E, T, Request, Encoding> FromReq<Put<Encoding>, Request, E> for T
where Request: Req<E> + Send + 'static, Encoding: Decodes<T>, E: FromServerFnError,

Source§

async fn from_req(req: Request) -> Result<T, E>

Attempts to deserialize the arguments from a request.
Source§

impl<E, Encoding, Response, T> FromRes<Patch<Encoding>, Response, E> for T
where Response: ClientRes<E> + Send, Encoding: Decodes<T>, E: FromServerFnError,

Source§

async fn from_res(res: Response) -> Result<T, E>

Attempts to deserialize the outputs from a response.
Source§

impl<E, Encoding, Response, T> FromRes<Post<Encoding>, Response, E> for T
where Response: ClientRes<E> + Send, Encoding: Decodes<T>, E: FromServerFnError,

Source§

async fn from_res(res: Response) -> Result<T, E>

Attempts to deserialize the outputs from a response.
Source§

impl<E, Encoding, Response, T> FromRes<Put<Encoding>, Response, E> for T
where Response: ClientRes<E> + Send, Encoding: Decodes<T>, E: FromServerFnError,

Source§

async fn from_res(res: Response) -> Result<T, E>

Attempts to deserialize the outputs from a response.
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<E, T, Encoding, Request> IntoReq<Patch<Encoding>, Request, E> for T
where Request: ClientReq<E>, Encoding: Encodes<T>, E: FromServerFnError,

Source§

fn into_req(self, path: &str, accepts: &str) -> Result<Request, E>

Attempts to serialize the arguments into an HTTP request.
Source§

impl<E, T, Encoding, Request> IntoReq<Post<Encoding>, Request, E> for T
where Request: ClientReq<E>, Encoding: Encodes<T>, E: FromServerFnError,

Source§

fn into_req(self, path: &str, accepts: &str) -> Result<Request, E>

Attempts to serialize the arguments into an HTTP request.
Source§

impl<E, T, Encoding, Request> IntoReq<Put<Encoding>, Request, E> for T
where Request: ClientReq<E>, Encoding: Encodes<T>, E: FromServerFnError,

Source§

fn into_req(self, path: &str, accepts: &str) -> Result<Request, E>

Attempts to serialize the arguments into an HTTP request.
Source§

impl<E, Response, Encoding, T> IntoRes<Patch<Encoding>, Response, E> for T
where Response: TryRes<E>, Encoding: Encodes<T>, E: FromServerFnError + Send, T: Send,

Source§

async fn into_res(self) -> Result<Response, E>

Attempts to serialize the output into an HTTP response.
Source§

impl<E, Response, Encoding, T> IntoRes<Post<Encoding>, Response, E> for T
where Response: TryRes<E>, Encoding: Encodes<T>, E: FromServerFnError + Send, T: Send,

Source§

async fn into_res(self) -> Result<Response, E>

Attempts to serialize the output into an HTTP response.
Source§

impl<E, Response, Encoding, T> IntoRes<Put<Encoding>, Response, E> for T
where Response: TryRes<E>, Encoding: Encodes<T>, E: FromServerFnError + Send, T: Send,

Source§

async fn into_res(self) -> Result<Response, E>

Attempts to serialize the output into an HTTP response.
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,