fix: apply some clippy lints and rename the liveview methods to not intersect

This commit is contained in:
Jonathan Kelley committed 2022-06-20 02:24:39 -04:00
1 parent c3e573b7cb
commit 8be66bd34d
14 files changed
+58 -76

No files matched your search

+19 -26
View File
@@ -1,36 +1,29 @@
use axum::{
extract::ws::WebSocketUpgrade, response::Html, response::IntoResponse, routing::get, Extension,
Router,
};
use axum::{extract::ws::WebSocketUpgrade, response::Html, routing::get, Router};
use dioxus_core::{Element, LazyNodes, Scope};
use dioxus_liveview::Liveview;
#[tokio::main]
async fn main() {
#[cfg(feature = "axum")]
{
pretty_env_logger::init();
pretty_env_logger::init();
let addr: std::net::SocketAddr = ([127, 0, 0, 1], 3030).into();
let addr: std::net::SocketAddr = ([127, 0, 0, 1], 3030).into();
let view = dioxus_liveview::new(addr);
let body = view.body("<title>Dioxus Liveview</title>");
let view = dioxus_liveview::new(addr);
let body = view.body("<title>Dioxus Liveview</title>");
let app = Router::new()
.route("/", get(move || async { Html(body) }))
.route(
"/app",
get(move |ws: WebSocketUpgrade| async move {
ws.on_upgrade(move |socket| async move {
view.upgrade(socket, app).await;
})
}),
);
axum::Server::bind(&addr.to_string().parse().unwrap())
.serve(app.into_make_service())
.await
.unwrap();
}
let app = Router::new()
.route("/", get(move || async { Html(body) }))
.route(
"/app",
get(move |ws: WebSocketUpgrade| async move {
ws.on_upgrade(move |socket| async move {
view.upgrade_axum(socket, app).await;
})
}),
);
axum::Server::bind(&addr.to_string().parse().unwrap())
.serve(app.into_make_service())
.await
.unwrap();
}
fn app(cx: Scope) -> Element {
+16 -19
View File
@@ -5,28 +5,25 @@ use warp::Filter;
#[tokio::main]
async fn main() {
#[cfg(feature = "warp")]
{
pretty_env_logger::init();
pretty_env_logger::init();
let addr = ([127, 0, 0, 1], 3030);
let addr = ([127, 0, 0, 1], 3030);
// todo: compactify this routing under one liveview::app method
let view = liveview::new(addr);
let body = view.body("<title>Dioxus LiveView</title>");
// todo: compactify this routing under one liveview::app method
let view = liveview::new(addr);
let body = view.body("<title>Dioxus LiveView</title>");
let routes = warp::path::end()
.map(move || warp::reply::html(body.clone()))
.or(warp::path("app")
.and(warp::ws())
.and(warp::any().map(move || view.clone()))
.map(|ws: Ws, view: liveview::Liveview| {
ws.on_upgrade(|socket| async move {
view.upgrade(socket, app).await;
})
}));
warp::serve(routes).run(addr).await;
}
let routes = warp::path::end()
.map(move || warp::reply::html(body.clone()))
.or(warp::path("app")
.and(warp::ws())
.and(warp::any().map(move || view.clone()))
.map(|ws: Ws, view: liveview::Liveview| {
ws.on_upgrade(|socket| async move {
view.upgrade_warp(socket, app).await;
})
}));
warp::serve(routes).run(addr).await;
}
fn app(cx: Scope) -> Element {