fix server actions and server multi actions

This commit is contained in:
Greg Johnston 2024-01-03 07:38:43 -05:00
parent 2dbc5899f3
commit dec17fc65b
2 changed files with 10 additions and 19 deletions

View File

@ -212,17 +212,17 @@ where
any(debug_assertions, feature = "ssr"),
tracing::instrument(level = "trace", skip_all,)
)]
pub fn server() -> Action<I, Result<I::Output, ServerFnError>>
pub fn server() -> Action<I, Result<I::Output, ServerFnError<I::Error>>>
where
I: ServerFn<Output = O> + Clone,
{
// The server is able to call the function directly
#[cfg(feature = "ssr")]
let action_function = |args: &I| I::call_fn(args.clone(), ());
let action_function = |args: &I| I::run_body(args.clone());
// When not on the server send a fetch to request the fn call.
#[cfg(not(feature = "ssr"))]
let action_function = |args: &I| I::call_fn_client(args.clone(), ());
let action_function = |args: &I| I::run_on_client(args.clone());
// create the action
Action::new(action_function).using_server_fn::<I>()
@ -267,13 +267,8 @@ where
tracing::instrument(level = "trace", skip_all,)
)]
pub fn using_server_fn<T: ServerFn>(self) -> Self {
let prefix = T::prefix();
self.0.update_value(|state| {
state.url = if prefix.is_empty() {
Some(T::url().to_string())
} else {
Some(prefix.to_string() + "/" + T::url())
};
state.url = Some(T::url().to_string());
});
self
}
@ -483,7 +478,8 @@ where
any(debug_assertions, feature = "ssr"),
tracing::instrument(level = "trace", skip_all,)
)]
pub fn create_server_action<S>() -> Action<S, Result<S::Output, ServerFnError>>
pub fn create_server_action<S>(
) -> Action<S, Result<S::Output, ServerFnError<S::Error>>>
where
S: Clone + ServerFn,
{

View File

@ -133,13 +133,8 @@ where
tracing::instrument(level = "trace", skip_all,)
)]
pub fn using_server_fn<T: ServerFn>(self) -> Self {
let prefix = T::prefix();
self.0.update_value(|a| {
a.url = if prefix.is_empty() {
Some(T::url().to_string())
} else {
Some(prefix.to_string() + "/" + T::url())
};
a.url = Some(T::url().to_string());
});
self
@ -343,13 +338,13 @@ where
tracing::instrument(level = "trace", skip_all,)
)]
pub fn create_server_multi_action<S>(
) -> MultiAction<S, Result<S::Output, ServerFnError>>
) -> MultiAction<S, Result<S::Output, ServerFnError<S::Error>>>
where
S: Clone + ServerFn,
{
#[cfg(feature = "ssr")]
let c = move |args: &S| S::call_fn(args.clone(), ());
let c = move |args: &S| S::run_body(args.clone());
#[cfg(not(feature = "ssr"))]
let c = move |args: &S| S::call_fn_client(args.clone(), ());
let c = move |args: &S| S::run_on_client(args.clone());
create_multi_action(c).using_server_fn::<S>()
}