Skip to content

Commit

Permalink
Fix leptos_server tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gbj committed Dec 28, 2022
1 parent f3b62bc commit 50ba796
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 32 deletions.
7 changes: 7 additions & 0 deletions leptos_server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,26 @@ syn = { version = "1", features = ["full", "parsing", "extra-traits"] }
proc-macro2 = "1.0.47"
ciborium = "0.2.0"

[dev-dependencies]
leptos = { path = "../leptos", default-features = false }

[features]
csr = [
"leptos/csr",
"leptos_dom/web",
"leptos_reactive/csr",
]
hydrate = [
"leptos/hydrate",
"leptos_dom/web",
"leptos_reactive/hydrate",
]
ssr = [
"leptos/ssr",
"leptos_reactive/ssr",
]
stable = [
"leptos/stable",
"leptos_dom/stable",
"leptos_reactive/stable",
]
Expand Down
20 changes: 7 additions & 13 deletions leptos_server/src/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ use std::{future::Future, pin::Pin, rc::Rc};
/// run an `async` function in response to something like a user clicking a button, you're in the right place.
///
/// ```rust
/// # use leptos_reactive::*;
/// # use leptos_server::create_action;
/// # use leptos::*;
/// # run_scope(create_runtime(), |cx| {
/// async fn send_new_todo_to_api(task: String) -> usize {
/// // do something...
Expand All @@ -37,7 +36,7 @@ use std::{future::Future, pin::Pin, rc::Rc};
/// assert_eq!(pending(), false); // isn't pending a response
/// assert_eq!(result_of_call(), None); // there's no "last value"
/// assert_eq!(version(), 0);
/// # if !cfg!(any(feature = "csr", feature = "hydrate")) {
/// # if false {
/// // dispatch the action
/// save_data.dispatch("My todo".to_string());
///
Expand All @@ -60,8 +59,7 @@ use std::{future::Future, pin::Pin, rc::Rc};
/// function, because it is stored in [Action::input] as well.
///
/// ```rust
/// # use leptos_reactive::*;
/// # use leptos_server::create_action;
/// # use leptos::*;
/// # run_scope(create_runtime(), |cx| {
/// // if there's a single argument, just use that
/// let action1 = create_action(cx, |input: &String| {
Expand Down Expand Up @@ -150,8 +148,7 @@ where
/// you're in the right place.
///
/// ```rust
/// # use leptos_reactive::*;
/// # use leptos_server::create_action;
/// # use leptos::*;
/// # run_scope(create_runtime(), |cx| {
/// async fn send_new_todo_to_api(task: String) -> usize {
/// // do something...
Expand All @@ -178,7 +175,7 @@ where
/// assert_eq!(pending(), false); // isn't pending a response
/// assert_eq!(result_of_call(), None); // there's no "last value"
/// assert_eq!(version(), 0);
/// # if !cfg!(any(feature = "csr", feature = "hydrate")) {
/// # if false {
/// // dispatch the action
/// save_data.dispatch("My todo".to_string());
///
Expand All @@ -201,8 +198,7 @@ where
/// function, because it is stored in [Action::input] as well.
///
/// ```rust
/// # use leptos_reactive::*;
/// # use leptos_server::create_action;
/// # use leptos::*;
/// # run_scope(create_runtime(), |cx| {
/// // if there's a single argument, just use that
/// let action1 = create_action(cx, |input: &String| {
Expand Down Expand Up @@ -246,9 +242,7 @@ where
/// Creates an [Action] that can be used to call a server function.
///
/// ```rust
/// # use leptos_reactive::*;
/// # use leptos_server::{create_server_action, ServerFnError, ServerFn};
/// # use leptos_macro::server;
/// # use leptos::*;
///
/// #[server(MyServerFn)]
/// async fn my_server_fn() -> Result<(), ServerFnError> {
Expand Down
9 changes: 3 additions & 6 deletions leptos_server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
//! crate that is enabled).
//!
//! ```rust,ignore
//! # use leptos_reactive::*;
//! # use leptos::*;
//! #[server(ReadFromDB)]
//! async fn read_posts(cx: Scope, how_many: usize, query: String) -> Result<Vec<Posts>, ServerFnError> {
//! // do some server-only work here to access the database
Expand Down Expand Up @@ -266,11 +266,8 @@ where
let value = match Self::encoding() {
Encoding::Url => serde_urlencoded::from_bytes(data)
.map_err(|e| ServerFnError::Deserialization(e.to_string())),
Encoding::Cbor => {
println!("Deserialize Cbor!: {:x?}", &data);
ciborium::de::from_reader(data)
.map_err(|e| ServerFnError::Deserialization(e.to_string()))
}
Encoding::Cbor => ciborium::de::from_reader(data)
.map_err(|e| ServerFnError::Deserialization(e.to_string())),
};
Box::pin(async move {
let value: Self = match value {
Expand Down
20 changes: 7 additions & 13 deletions leptos_server/src/multi_action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ use std::{future::Future, pin::Pin, rc::Rc};
/// you’re in the right place.
///
/// ```rust
/// # use leptos_reactive::*;
/// # use leptos_server::create_multi_action;
/// # use leptos::*;
/// # run_scope(create_runtime(), |cx| {
/// async fn send_new_todo_to_api(task: String) -> usize {
/// // do something...
Expand All @@ -27,7 +26,7 @@ use std::{future::Future, pin::Pin, rc::Rc};
/// send_new_todo_to_api(task.clone())
/// });
///
/// # if !cfg!(any(feature = "csr", feature = "hydrate")) {
/// # if false {
/// add_todo.dispatch("Buy milk".to_string());
/// add_todo.dispatch("???".to_string());
/// add_todo.dispatch("Profit!!!".to_string());
Expand All @@ -41,8 +40,7 @@ use std::{future::Future, pin::Pin, rc::Rc};
/// function, because it is stored in [Submission::input] as well.
///
/// ```rust
/// # use leptos_reactive::*;
/// # use leptos_server::create_multi_action;
/// # use leptos::*;
/// # run_scope(create_runtime(), |cx| {
/// // if there's a single argument, just use that
/// let action1 = create_multi_action(cx, |input: &String| {
Expand Down Expand Up @@ -186,8 +184,7 @@ where
/// you're in the right place.
///
/// ```rust
/// # use leptos_reactive::*;
/// # use leptos_server::create_multi_action;
/// # use leptos::*;
/// # run_scope(create_runtime(), |cx| {
/// async fn send_new_todo_to_api(task: String) -> usize {
/// // do something...
Expand All @@ -198,7 +195,7 @@ where
/// // `task` is given as `&String` because its value is available in `input`
/// send_new_todo_to_api(task.clone())
/// });
/// # if !cfg!(any(feature = "csr", feature = "hydrate")) {
/// # if false {
///
/// add_todo.dispatch("Buy milk".to_string());
/// add_todo.dispatch("???".to_string());
Expand All @@ -214,8 +211,7 @@ where
/// function, because it is stored in [Submission::input] as well.
///
/// ```rust
/// # use leptos_reactive::*;
/// # use leptos_server::create_multi_action;
/// # use leptos::*;
/// # run_scope(create_runtime(), |cx| {
/// // if there's a single argument, just use that
/// let action1 = create_multi_action(cx, |input: &String| {
Expand Down Expand Up @@ -256,9 +252,7 @@ where
/// Creates an [MultiAction] that can be used to call a server function.
///
/// ```rust
/// # use leptos_reactive::*;
/// # use leptos_server::{create_server_multi_action, ServerFnError, ServerFn};
/// # use leptos_macro::server;
/// # use leptos::*;
///
/// #[server(MyServerFn)]
/// async fn my_server_fn() -> Result<(), ServerFnError> {
Expand Down

0 comments on commit 50ba796

Please sign in to comment.