remove old references to server context
This commit is contained in:
1 parent
fb042df2fb
commit
41f9c480c8
5 files changed
+16
-21
No files matched your search
@@ -74,10 +74,9 @@ fn app(cx: Scope<usize>) -> Element {
|
|||||||
button {
|
button {
|
||||||
onclick: move |_| {
|
onclick: move |_| {
|
||||||
to_owned![count];
|
to_owned![count];
|
||||||
let sc = cx.sc();
|
|
||||||
async move {
|
async move {
|
||||||
// Call the server function just like a local async function
|
// Call the server function just like a local async function
|
||||||
if let Ok(new_count) = double_server(sc, *count.current()).await {
|
if let Ok(new_count) = double_server(*count.current()).await {
|
||||||
count.set(new_count);
|
count.set(new_count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -89,7 +88,8 @@ fn app(cx: Scope<usize>) -> Element {
|
|||||||
|
|
||||||
// We use the "getcbor" encoding to make caching easier
|
// We use the "getcbor" encoding to make caching easier
|
||||||
#[server(DoubleServer, "", "getcbor")]
|
#[server(DoubleServer, "", "getcbor")]
|
||||||
async fn double_server(cx: DioxusServerContext, number: usize) -> Result<usize, ServerFnError> {
|
async fn double_server(number: usize) -> Result<usize, ServerFnError> {
|
||||||
|
let cx = server_context();
|
||||||
// Perform some expensive computation or access a database on the server
|
// Perform some expensive computation or access a database on the server
|
||||||
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
|
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
|
||||||
let result = number * 2;
|
let result = number * 2;
|
||||||
|
|||||||
@@ -92,10 +92,9 @@ fn app(cx: Scope<usize>) -> Element {
|
|||||||
button {
|
button {
|
||||||
onclick: move |_| {
|
onclick: move |_| {
|
||||||
to_owned![count];
|
to_owned![count];
|
||||||
let sc = cx.sc();
|
|
||||||
async move {
|
async move {
|
||||||
// Call the server function just like a local async function
|
// Call the server function just like a local async function
|
||||||
if let Ok(new_count) = double_server(sc, *count.current()).await {
|
if let Ok(new_count) = double_server(*count.current()).await {
|
||||||
count.set(new_count);
|
count.set(new_count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -107,10 +106,11 @@ fn app(cx: Scope<usize>) -> Element {
|
|||||||
|
|
||||||
// We use the "getcbor" encoding to make caching easier
|
// We use the "getcbor" encoding to make caching easier
|
||||||
#[server(DoubleServer, "", "getcbor")]
|
#[server(DoubleServer, "", "getcbor")]
|
||||||
async fn double_server(cx: DioxusServerContext, number: usize) -> Result<usize, ServerFnError> {
|
async fn double_server(number: usize) -> Result<usize, ServerFnError> {
|
||||||
// Perform some expensive computation or access a database on the server
|
// Perform some expensive computation or access a database on the server
|
||||||
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
|
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
|
||||||
let result = number * 2;
|
let result = number * 2;
|
||||||
|
let cx = server_context();
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
"User Agent {:?}",
|
"User Agent {:?}",
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ struct AppProps {
|
|||||||
fn app(cx: Scope<AppProps>) -> Element {
|
fn app(cx: Scope<AppProps>) -> Element {
|
||||||
let mut count = use_state(cx, || cx.props.count);
|
let mut count = use_state(cx, || cx.props.count);
|
||||||
let text = use_state(cx, || "...".to_string());
|
let text = use_state(cx, || "...".to_string());
|
||||||
let server_context = cx.sc();
|
|
||||||
|
|
||||||
cx.render(rsx! {
|
cx.render(rsx! {
|
||||||
h1 { "High-Five counter: {count}" }
|
h1 { "High-Five counter: {count}" }
|
||||||
@@ -32,12 +31,12 @@ fn app(cx: Scope<AppProps>) -> Element {
|
|||||||
button { onclick: move |_| count -= 1, "Down low!" }
|
button { onclick: move |_| count -= 1, "Down low!" }
|
||||||
button {
|
button {
|
||||||
onclick: move |_| {
|
onclick: move |_| {
|
||||||
to_owned![text, server_context];
|
to_owned![text];
|
||||||
async move {
|
async move {
|
||||||
if let Ok(data) = get_server_data().await {
|
if let Ok(data) = get_server_data().await {
|
||||||
println!("Client received: {}", data);
|
println!("Client received: {}", data);
|
||||||
text.set(data.clone());
|
text.set(data.clone());
|
||||||
post_server_data(server_context, data).await.unwrap();
|
post_server_data(data).await.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -48,8 +47,9 @@ fn app(cx: Scope<AppProps>) -> Element {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[server(PostServerData)]
|
#[server(PostServerData)]
|
||||||
async fn post_server_data(cx: DioxusServerContext, data: String) -> Result<(), ServerFnError> {
|
async fn post_server_data(data: String) -> Result<(), ServerFnError> {
|
||||||
// The server context contains information about the current request and allows you to modify the response.
|
// The server context contains information about the current request and allows you to modify the response.
|
||||||
|
let cx = server_context();
|
||||||
cx.response_headers_mut()
|
cx.response_headers_mut()
|
||||||
.insert("Set-Cookie", "foo=bar".parse().unwrap());
|
.insert("Set-Cookie", "foo=bar".parse().unwrap());
|
||||||
println!("Server received: {}", data);
|
println!("Server received: {}", data);
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ struct AppProps {
|
|||||||
fn app(cx: Scope<AppProps>) -> Element {
|
fn app(cx: Scope<AppProps>) -> Element {
|
||||||
let mut count = use_state(cx, || cx.props.count);
|
let mut count = use_state(cx, || cx.props.count);
|
||||||
let text = use_state(cx, || "...".to_string());
|
let text = use_state(cx, || "...".to_string());
|
||||||
let server_context = cx.sc();
|
|
||||||
|
|
||||||
cx.render(rsx! {
|
cx.render(rsx! {
|
||||||
h1 { "High-Five counter: {count}" }
|
h1 { "High-Five counter: {count}" }
|
||||||
@@ -32,12 +31,12 @@ fn app(cx: Scope<AppProps>) -> Element {
|
|||||||
button { onclick: move |_| count -= 1, "Down low!" }
|
button { onclick: move |_| count -= 1, "Down low!" }
|
||||||
button {
|
button {
|
||||||
onclick: move |_| {
|
onclick: move |_| {
|
||||||
to_owned![text, server_context];
|
to_owned![text];
|
||||||
async move {
|
async move {
|
||||||
if let Ok(data) = get_server_data().await {
|
if let Ok(data) = get_server_data().await {
|
||||||
println!("Client received: {}", data);
|
println!("Client received: {}", data);
|
||||||
text.set(data.clone());
|
text.set(data.clone());
|
||||||
post_server_data(server_context, data).await.unwrap();
|
post_server_data(data).await.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -48,8 +47,9 @@ fn app(cx: Scope<AppProps>) -> Element {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[server(PostServerData)]
|
#[server(PostServerData)]
|
||||||
async fn post_server_data(cx: DioxusServerContext, data: String) -> Result<(), ServerFnError> {
|
async fn post_server_data(data: String) -> Result<(), ServerFnError> {
|
||||||
// The server context contains information about the current request and allows you to modify the response.
|
// The server context contains information about the current request and allows you to modify the response.
|
||||||
|
let cx = server_context();
|
||||||
cx.response_headers_mut()
|
cx.response_headers_mut()
|
||||||
.insert("Set-Cookie", "foo=bar".parse().unwrap());
|
.insert("Set-Cookie", "foo=bar".parse().unwrap());
|
||||||
println!("Server received: {}", data);
|
println!("Server received: {}", data);
|
||||||
|
|||||||
@@ -69,12 +69,11 @@ fn app(cx: Scope<AppProps>) -> Element {
|
|||||||
class: "server-button",
|
class: "server-button",
|
||||||
onclick: move |_| {
|
onclick: move |_| {
|
||||||
to_owned![text];
|
to_owned![text];
|
||||||
let sc = cx.sc();
|
|
||||||
async move {
|
async move {
|
||||||
if let Ok(data) = get_server_data().await {
|
if let Ok(data) = get_server_data().await {
|
||||||
println!("Client received: {}", data);
|
println!("Client received: {}", data);
|
||||||
text.set(data.clone());
|
text.set(data.clone());
|
||||||
post_server_data(sc, data).await.unwrap();
|
post_server_data(data).await.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -85,12 +84,8 @@ fn app(cx: Scope<AppProps>) -> Element {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[server(PostServerData)]
|
#[server(PostServerData)]
|
||||||
async fn post_server_data(cx: DioxusServerContext, data: String) -> Result<(), ServerFnError> {
|
async fn post_server_data(data: String) -> Result<(), ServerFnError> {
|
||||||
// The server context contains information about the current request and allows you to modify the response.
|
|
||||||
cx.response_headers_mut()
|
|
||||||
.insert("Set-Cookie", "foo=bar".parse().unwrap());
|
|
||||||
println!("Server received: {}", data);
|
println!("Server received: {}", data);
|
||||||
println!("Request parts are {:?}", cx.request_parts());
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user