remove async demo

This commit is contained in:
Greg Johnston 2024-06-03 08:07:18 -04:00
parent e275862a20
commit 770d02d8e6
8 changed files with 0 additions and 191 deletions

View File

@ -1,23 +0,0 @@
[package]
name = "async-demo"
version = "0.1.0"
edition = "2021"
[profile.release]
codegen-units = 1
lto = true
[dependencies]
leptos = { path = "../../leptos", features = ["csr", "nightly"] }
reqwasm = "0.5"
serde = { version = "1", features = ["derive"] }
log = "0.4"
console_log = "1"
console_error_panic_hook = "0.1"
thiserror = "1"
send_wrapper = { version = "0.6.0", features = ["futures"] }
gloo-timers = { version = "0.3.0", features = ["futures"] }
futures = "0.3.30"
[dev-dependencies]
wasm-bindgen-test = "0.3"

View File

@ -1,4 +0,0 @@
extend = [
{ path = "../cargo-make/main.toml" },
{ path = "../cargo-make/trunk_server.toml" },
]

View File

@ -1,11 +0,0 @@
# Client Side Fetch
This example shows how to fetch data from the client in WebAssembly.
## Getting Started
See the [Examples README](../README.md) for setup and run instructions.
## Quick Start
Run `trunk serve --open` to run this example.

View File

@ -1,21 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<link data-trunk rel="rust" data-wasm-opt="z"/>
<link data-trunk rel="icon" type="image/ico" href="/public/favicon.ico"/>
<meta name="color-scheme" content="light dark"/>
</head>
<style>
img {
max-width: 250px;
height: auto;
}
.error {
border: 1px solid red;
color: red;
background-color: lightpink;
}
</style>
<body></body>
</html>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

View File

@ -1,2 +0,0 @@
[toolchain]
channel = "nightly-2024-01-29"

View File

@ -1,122 +0,0 @@
use gloo_timers::future::TimeoutFuture;
use leptos::{
prelude::*,
reactive_graph::{
computed::{AsyncDerived, AsyncState},
signal::RwSignal,
},
tachys::log,
view, IntoView,
};
use send_wrapper::SendWrapper;
use std::future::{Future, IntoFuture};
fn wait(
id: char,
seconds: u8,
value: u32,
) -> impl Future<Output = u32> + Send + Sync {
SendWrapper::new(async move {
log(&format!("loading data for {id}"));
TimeoutFuture::new(seconds as u32 * 1000).await;
value + 1
})
}
fn sleep(seconds: u32) -> impl Future<Output = ()> + Send + Sync {
SendWrapper::new(async move {
TimeoutFuture::new(seconds * 1000).await;
})
}
pub fn async_example() -> impl IntoView {
let a = RwSignal::new(0);
let b = RwSignal::new(1);
let a2 = || wait('A', 1, 1);
let b2 = || wait('B', 3, 3);
//let a2 = create_resource(a, |a| wait('A', 1, a));
//let b2 = create_resource(b, |a| wait('A', 1, b));
view! {
<button on:click=move |_| a.update(|n| *n += 1)> {a} </button> " "
<button on:click=move |_| b.update(|n| *n += 1)> {b} </button>
/*<Suspense>
{move || a2().map(move |a2| {
b2().map(move |b2| {
view! {
<p>{a2} + {b2}</p>
}
})
})}
</Suspense>*/
<p>
//{times}
</p>
}
}
/*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
pub fn notes() -> impl IntoView {
let a = RwSignal::new(0);
let b = RwSignal::new(1);
let a2 = AsyncDerived::new(move || wait('A', 1, a.get()));
let b2 = AsyncDerived::new(move || wait('B', 3, b.get()));
let c = AsyncDerived::new(move || async move {
sleep(1).await;
a2.await + b2.await
});
let a_and_b = move || {
async move { (a2.await, " + ", b2.await) }
.suspend()
.with_fallback("Loading A and B...")
.track()
};
let c = move || {
c.into_future()
.suspend()
.with_fallback("Loading C...")
.track()
};
view! {
<button on:click=move |_| {
a.update(|n| *n += 1);
}>
{a}
</button>
<button on:click=move |_| {
b.update(|n| *n += 1);
}>
{b}
</button>
<p> {a_and_b} </p>
<p> {c} </p>
}
}

View File

@ -1,8 +0,0 @@
use async_demo::async_example;
use leptos::*;
pub fn main() {
_ = console_log::init_with_level(log::Level::Debug);
console_error_panic_hook::set_once();
mount_to_body(async_example)
}