diff --git a/benches/tui_update.rs b/benches/tui_update.rs index d46921a8d..811c40739 100644 --- a/benches/tui_update.rs +++ b/benches/tui_update.rs @@ -80,11 +80,11 @@ fn Grid(cx: Scope) -> Element { counts.with_mut(|c| { let i = *count.current(); c[i] += 1; - c[i] = c[i] % 360; + c[i] %= 360; }); count.with_mut(|i| { *i += 1; - *i = *i % (size * size); + *i %= size * size; }); } diff --git a/examples/tui_keys.rs b/examples/tui_keys.rs index 138eec2fe..91c42e30e 100644 --- a/examples/tui_keys.rs +++ b/examples/tui_keys.rs @@ -11,9 +11,9 @@ fn main() { fn app(cx: Scope) -> Element { let key = use_state(&cx, || "".to_string()); - let mouse = use_state(&cx, || ScreenPoint::zero()); + let mouse = use_state(&cx, ScreenPoint::zero); let count = use_state(&cx, || 0); - let buttons = use_state(&cx, || MouseButtonSet::empty()); + let buttons = use_state(&cx, MouseButtonSet::empty); let mouse_clicked = use_state(&cx, || false); cx.render(rsx! { diff --git a/packages/html/src/web_sys_bind/events.rs b/packages/html/src/web_sys_bind/events.rs index a69ac5fef..670b211c0 100644 --- a/packages/html/src/web_sys_bind/events.rs +++ b/packages/html/src/web_sys_bind/events.rs @@ -96,7 +96,7 @@ impl From<&MouseEvent> for MouseData { ElementPoint::new(e.offset_x().into(), e.offset_y().into()), PagePoint::new(e.page_x().into(), e.page_y().into()), ), - Some(MouseButton::from_web_code(e.button().into())), + Some(MouseButton::from_web_code(e.button())), decode_mouse_button_set(e.buttons()), modifiers, ) diff --git a/packages/liveview/examples/axum.rs b/packages/liveview/examples/axum.rs index 3bcdee8c2..5983e304d 100644 --- a/packages/liveview/examples/axum.rs +++ b/packages/liveview/examples/axum.rs @@ -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("Dioxus Liveview"); + let view = dioxus_liveview::new(addr); + let body = view.body("Dioxus Liveview"); - 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 { diff --git a/packages/liveview/examples/warp.rs b/packages/liveview/examples/warp.rs index 2c14d318b..dcece1ae8 100644 --- a/packages/liveview/examples/warp.rs +++ b/packages/liveview/examples/warp.rs @@ -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("Dioxus LiveView"); + // todo: compactify this routing under one liveview::app method + let view = liveview::new(addr); + let body = view.body("Dioxus LiveView"); - 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 { diff --git a/packages/liveview/src/adapters/actix_adapter.rs b/packages/liveview/src/adapters/actix_adapter.rs deleted file mode 100644 index 8b1378917..000000000 --- a/packages/liveview/src/adapters/actix_adapter.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/packages/liveview/src/adapters/axum_adapter.rs b/packages/liveview/src/adapters/axum_adapter.rs index 4122950bc..c60b267ea 100644 --- a/packages/liveview/src/adapters/axum_adapter.rs +++ b/packages/liveview/src/adapters/axum_adapter.rs @@ -1,4 +1,4 @@ -use crate::{events, Liveview}; +use crate::events; use axum::extract::ws::{Message, WebSocket}; use dioxus_core::prelude::*; use futures_util::{ @@ -10,11 +10,16 @@ use tokio_stream::wrappers::UnboundedReceiverStream; use tokio_util::task::LocalPoolHandle; impl crate::Liveview { - pub async fn upgrade(&self, ws: WebSocket, app: fn(Scope) -> Element) { + pub async fn upgrade_axum(&self, ws: WebSocket, app: fn(Scope) -> Element) { connect(ws, self.pool.clone(), app, ()).await; } - pub async fn upgrade_with_props(&self, ws: WebSocket, app: fn(Scope) -> Element, props: T) - where + + pub async fn upgrade_axum_with_props( + &self, + ws: WebSocket, + app: fn(Scope) -> Element, + props: T, + ) where T: Send + Sync + 'static, { connect(ws, self.pool.clone(), app, props).await; diff --git a/packages/liveview/src/adapters/warp_adapter.rs b/packages/liveview/src/adapters/warp_adapter.rs index f3cf3914b..398c7cdd9 100644 --- a/packages/liveview/src/adapters/warp_adapter.rs +++ b/packages/liveview/src/adapters/warp_adapter.rs @@ -7,10 +7,10 @@ use tokio_util::task::LocalPoolHandle; use warp::ws::{Message, WebSocket}; impl crate::Liveview { - pub async fn upgrade(&self, ws: warp::ws::WebSocket, app: fn(Scope) -> Element) { + pub async fn upgrade_warp(&self, ws: warp::ws::WebSocket, app: fn(Scope) -> Element) { connect(ws, self.pool.clone(), app, ()).await; } - pub async fn upgrade_with_props( + pub async fn upgrade_warp_with_props( &self, ws: warp::ws::WebSocket, app: fn(Scope) -> Element, diff --git a/packages/liveview/src/lib.rs b/packages/liveview/src/lib.rs index f3ad90511..2f1cd3b9b 100644 --- a/packages/liveview/src/lib.rs +++ b/packages/liveview/src/lib.rs @@ -7,21 +7,10 @@ pub mod adapters { #[cfg(feature = "axum")] pub mod axum_adapter; - - #[cfg(feature = "actix")] - pub mod actix_adapter; } use std::net::SocketAddr; -#[cfg(feature = "warp")] -pub use adapters::warp_adapter::connect; - -#[cfg(feature = "axum")] -pub use adapters::axum_adapter::connect; - -#[cfg(feature = "actix")] -pub use adapters::actix_adapter::connect; use tokio_util::task::LocalPoolHandle; #[derive(Clone)] diff --git a/packages/native-core-macro/src/lib.rs b/packages/native-core-macro/src/lib.rs index 508754bf7..58fa3e3a9 100644 --- a/packages/native-core-macro/src/lib.rs +++ b/packages/native-core-macro/src/lib.rs @@ -211,7 +211,7 @@ fn impl_derive_macro(ast: &syn::DeriveInput) -> TokenStream { ty: dioxus_native_core::state::MemberId, node: &'a dioxus_core::VNode<'a>, vdom: &'a dioxus_core::VirtualDom, - children: &Vec<&Self>, + children: &[&Self], ctx: &anymap::AnyMap, ) -> Option{ use dioxus_native_core::state::ChildDepState as _; @@ -225,7 +225,7 @@ fn impl_derive_macro(ast: &syn::DeriveInput) -> TokenStream { ty - #sum_idents, node, vdom, - &children.iter().map(|p| &p.#child_state_idents).collect(), + &children.iter().map(|p| &p.#child_state_idents).collect::>(), ctx, ).map(|mut changed|{ for id in &mut changed.node_dep{ diff --git a/packages/native-core-macro/tests/update_state.rs b/packages/native-core-macro/tests/update_state.rs index 5cd23732e..84ec5d530 100644 --- a/packages/native-core-macro/tests/update_state.rs +++ b/packages/native-core-macro/tests/update_state.rs @@ -92,6 +92,7 @@ impl NodeDepState for NodeDepCallCounter { } } +#[allow(clippy::vec_box)] #[derive(Debug, Clone, PartialEq, Default)] struct BubbledUpStateTester(Option, Vec>); impl ChildDepState for BubbledUpStateTester { diff --git a/packages/native-core/src/state.rs b/packages/native-core/src/state.rs index 7583e3ede..89c47e6e9 100644 --- a/packages/native-core/src/state.rs +++ b/packages/native-core/src/state.rs @@ -132,7 +132,7 @@ pub trait State: Default + Clone { ty: MemberId, node: &'a VNode<'a>, vdom: &'a dioxus_core::VirtualDom, - children: &Vec<&Self>, + children: &[&Self], ctx: &AnyMap, ) -> Option; /// This must be a valid resolution order. (no nodes updated before a state they rely on) diff --git a/packages/tui/src/focus.rs b/packages/tui/src/focus.rs index 18e2fbd3f..c2806d5e7 100644 --- a/packages/tui/src/focus.rs +++ b/packages/tui/src/focus.rs @@ -74,7 +74,7 @@ impl NodeDepState for Focus { if let Some(index) = a .value .as_int32() - .or(a.value.as_text().and_then(|v| v.parse::().ok())) + .or_else(|| a.value.as_text().and_then(|v| v.parse::().ok())) { match index.cmp(&0) { Ordering::Less => FocusLevel::Unfocusable, diff --git a/packages/tui/src/hooks.rs b/packages/tui/src/hooks.rs index b62cc256c..03cfd90e2 100644 --- a/packages/tui/src/hooks.rs +++ b/packages/tui/src/hooks.rs @@ -545,11 +545,9 @@ impl InnerInputState { } fn get_abs_layout(node: &Node, dom: &Dom, taffy: &Taffy) -> Layout { - let mut node_layout = taffy - .layout(node.state.layout.node.unwrap()) - .unwrap() - .clone(); + let mut node_layout = *taffy.layout(node.state.layout.node.unwrap()).unwrap(); let mut current = node; + while let Some(parent_id) = current.parent { let parent = &dom[parent_id]; current = parent;