wip: more refactor for async
This commit is contained in:
1 parent
8cfc437bfe
commit
975fa566f9
18 files changed
+110
-122
No files matched your search
+13
-38
@@ -7,7 +7,9 @@ use std::pin::Pin;
|
||||
use dioxus::prelude::*;
|
||||
use futures::Future;
|
||||
fn main() {
|
||||
dioxus::web::launch(App)
|
||||
env_logger::init();
|
||||
log::info!("hello world");
|
||||
dioxus::desktop::launch(App, |c| c).expect("faield to launch");
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
@@ -17,58 +19,31 @@ struct DogApi {
|
||||
|
||||
const ENDPOINT: &str = "https://dog.ceo/api/breeds/image/random";
|
||||
|
||||
struct Ex(Pin<Box<dyn Future<Output = ()> + 'static>>);
|
||||
static App: FC<()> = |cx| {
|
||||
// let mut count = use_state(cx, || 0);
|
||||
let mut fut = cx.use_hook(
|
||||
move || {
|
||||
Box::pin(async {
|
||||
Ex(Box::pin(async {
|
||||
//
|
||||
loop {
|
||||
// repeatadly get new doggos
|
||||
match surf::get(ENDPOINT).recv_json::<DogApi>().await {
|
||||
Ok(_) => (),
|
||||
Err(_) => (),
|
||||
// Ok(res) => rsx!(in cx, img { src: "{res.message}" }),
|
||||
// Err(_) => rsx!(in cx, div { "No doggos for you :(" }),
|
||||
}
|
||||
// wait one seconds
|
||||
}
|
||||
}) as Pin<Box<dyn Future<Output = ()> + 'static>>
|
||||
})
|
||||
as Pin<Box<dyn Future<Output = ()> + 'static>>)
|
||||
},
|
||||
|h| h,
|
||||
|h| &mut h.0,
|
||||
|_| {},
|
||||
);
|
||||
|
||||
cx.submit_task(fut);
|
||||
|
||||
todo!()
|
||||
// cx.render(rsx! {
|
||||
// div {
|
||||
// h1 { "Hifive counter: {count}" }
|
||||
// button { onclick: move |_| count += 1, "Up high!" }
|
||||
// button { onclick: move |_| count -= 1, "Down low!" }
|
||||
// }
|
||||
// })
|
||||
cx.render(rsx! {
|
||||
div {
|
||||
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
// #[derive(serde::Deserialize)]
|
||||
// struct DogApi {
|
||||
// message: String,
|
||||
// }
|
||||
// const ENDPOINT: &str = "https://dog.ceo/api/breeds/image/random";
|
||||
|
||||
// pub static App: FC<()> = |cx| {
|
||||
// let doggo = use_future_effect(&cx, move || async move {
|
||||
// match surf::get(ENDPOINT).recv_json::<DogApi>().await {
|
||||
// Ok(res) => rsx!(in cx, img { src: "{res.message}" }),
|
||||
// Err(_) => rsx!(in cx, div { "No doggos for you :(" }),
|
||||
// }
|
||||
// });
|
||||
|
||||
// cx.render(rsx!(
|
||||
// div {
|
||||
// h1 {"Waiting for a doggo..."}
|
||||
// {doggo}
|
||||
// }
|
||||
// ))
|
||||
// };
|
||||
Reference in new issue
Block a user