mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-23 12:43:08 +00:00
fix: apply some clippy lints and rename the liveview methods to not intersect
This commit is contained in:
parent
c3e573b7cb
commit
8be66bd34d
14 changed files with 58 additions and 76 deletions
|
@ -80,11 +80,11 @@ fn Grid(cx: Scope<GridProps>) -> Element {
|
||||||
counts.with_mut(|c| {
|
counts.with_mut(|c| {
|
||||||
let i = *count.current();
|
let i = *count.current();
|
||||||
c[i] += 1;
|
c[i] += 1;
|
||||||
c[i] = c[i] % 360;
|
c[i] %= 360;
|
||||||
});
|
});
|
||||||
count.with_mut(|i| {
|
count.with_mut(|i| {
|
||||||
*i += 1;
|
*i += 1;
|
||||||
*i = *i % (size * size);
|
*i %= size * size;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,9 +11,9 @@ fn main() {
|
||||||
|
|
||||||
fn app(cx: Scope) -> Element {
|
fn app(cx: Scope) -> Element {
|
||||||
let key = use_state(&cx, || "".to_string());
|
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 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);
|
let mouse_clicked = use_state(&cx, || false);
|
||||||
|
|
||||||
cx.render(rsx! {
|
cx.render(rsx! {
|
||||||
|
|
|
@ -96,7 +96,7 @@ impl From<&MouseEvent> for MouseData {
|
||||||
ElementPoint::new(e.offset_x().into(), e.offset_y().into()),
|
ElementPoint::new(e.offset_x().into(), e.offset_y().into()),
|
||||||
PagePoint::new(e.page_x().into(), e.page_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()),
|
decode_mouse_button_set(e.buttons()),
|
||||||
modifiers,
|
modifiers,
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,14 +1,8 @@
|
||||||
use axum::{
|
use axum::{extract::ws::WebSocketUpgrade, response::Html, routing::get, Router};
|
||||||
extract::ws::WebSocketUpgrade, response::Html, response::IntoResponse, routing::get, Extension,
|
|
||||||
Router,
|
|
||||||
};
|
|
||||||
use dioxus_core::{Element, LazyNodes, Scope};
|
use dioxus_core::{Element, LazyNodes, Scope};
|
||||||
use dioxus_liveview::Liveview;
|
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn 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();
|
||||||
|
@ -22,7 +16,7 @@ async fn main() {
|
||||||
"/app",
|
"/app",
|
||||||
get(move |ws: WebSocketUpgrade| async move {
|
get(move |ws: WebSocketUpgrade| async move {
|
||||||
ws.on_upgrade(move |socket| async move {
|
ws.on_upgrade(move |socket| async move {
|
||||||
view.upgrade(socket, app).await;
|
view.upgrade_axum(socket, app).await;
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
@ -30,7 +24,6 @@ async fn main() {
|
||||||
.serve(app.into_make_service())
|
.serve(app.into_make_service())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn app(cx: Scope) -> Element {
|
fn app(cx: Scope) -> Element {
|
||||||
|
|
|
@ -5,8 +5,6 @@ use warp::Filter;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn 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);
|
||||||
|
@ -22,11 +20,10 @@ async fn main() {
|
||||||
.and(warp::any().map(move || view.clone()))
|
.and(warp::any().map(move || view.clone()))
|
||||||
.map(|ws: Ws, view: liveview::Liveview| {
|
.map(|ws: Ws, view: liveview::Liveview| {
|
||||||
ws.on_upgrade(|socket| async move {
|
ws.on_upgrade(|socket| async move {
|
||||||
view.upgrade(socket, app).await;
|
view.upgrade_warp(socket, app).await;
|
||||||
})
|
})
|
||||||
}));
|
}));
|
||||||
warp::serve(routes).run(addr).await;
|
warp::serve(routes).run(addr).await;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn app(cx: Scope) -> Element {
|
fn app(cx: Scope) -> Element {
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{events, Liveview};
|
use crate::events;
|
||||||
use axum::extract::ws::{Message, WebSocket};
|
use axum::extract::ws::{Message, WebSocket};
|
||||||
use dioxus_core::prelude::*;
|
use dioxus_core::prelude::*;
|
||||||
use futures_util::{
|
use futures_util::{
|
||||||
|
@ -10,11 +10,16 @@ use tokio_stream::wrappers::UnboundedReceiverStream;
|
||||||
use tokio_util::task::LocalPoolHandle;
|
use tokio_util::task::LocalPoolHandle;
|
||||||
|
|
||||||
impl crate::Liveview {
|
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;
|
connect(ws, self.pool.clone(), app, ()).await;
|
||||||
}
|
}
|
||||||
pub async fn upgrade_with_props<T>(&self, ws: WebSocket, app: fn(Scope<T>) -> Element, props: T)
|
|
||||||
where
|
pub async fn upgrade_axum_with_props<T>(
|
||||||
|
&self,
|
||||||
|
ws: WebSocket,
|
||||||
|
app: fn(Scope<T>) -> Element,
|
||||||
|
props: T,
|
||||||
|
) where
|
||||||
T: Send + Sync + 'static,
|
T: Send + Sync + 'static,
|
||||||
{
|
{
|
||||||
connect(ws, self.pool.clone(), app, props).await;
|
connect(ws, self.pool.clone(), app, props).await;
|
||||||
|
|
|
@ -7,10 +7,10 @@ use tokio_util::task::LocalPoolHandle;
|
||||||
use warp::ws::{Message, WebSocket};
|
use warp::ws::{Message, WebSocket};
|
||||||
|
|
||||||
impl crate::Liveview {
|
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;
|
connect(ws, self.pool.clone(), app, ()).await;
|
||||||
}
|
}
|
||||||
pub async fn upgrade_with_props<T>(
|
pub async fn upgrade_warp_with_props<T>(
|
||||||
&self,
|
&self,
|
||||||
ws: warp::ws::WebSocket,
|
ws: warp::ws::WebSocket,
|
||||||
app: fn(Scope<T>) -> Element,
|
app: fn(Scope<T>) -> Element,
|
||||||
|
|
|
@ -7,21 +7,10 @@ pub mod adapters {
|
||||||
|
|
||||||
#[cfg(feature = "axum")]
|
#[cfg(feature = "axum")]
|
||||||
pub mod axum_adapter;
|
pub mod axum_adapter;
|
||||||
|
|
||||||
#[cfg(feature = "actix")]
|
|
||||||
pub mod actix_adapter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
use std::net::SocketAddr;
|
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;
|
use tokio_util::task::LocalPoolHandle;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
|
|
@ -211,7 +211,7 @@ fn impl_derive_macro(ast: &syn::DeriveInput) -> TokenStream {
|
||||||
ty: dioxus_native_core::state::MemberId,
|
ty: dioxus_native_core::state::MemberId,
|
||||||
node: &'a dioxus_core::VNode<'a>,
|
node: &'a dioxus_core::VNode<'a>,
|
||||||
vdom: &'a dioxus_core::VirtualDom,
|
vdom: &'a dioxus_core::VirtualDom,
|
||||||
children: &Vec<&Self>,
|
children: &[&Self],
|
||||||
ctx: &anymap::AnyMap,
|
ctx: &anymap::AnyMap,
|
||||||
) -> Option<dioxus_native_core::state::ChildStatesChanged>{
|
) -> Option<dioxus_native_core::state::ChildStatesChanged>{
|
||||||
use dioxus_native_core::state::ChildDepState as _;
|
use dioxus_native_core::state::ChildDepState as _;
|
||||||
|
@ -225,7 +225,7 @@ fn impl_derive_macro(ast: &syn::DeriveInput) -> TokenStream {
|
||||||
ty - #sum_idents,
|
ty - #sum_idents,
|
||||||
node,
|
node,
|
||||||
vdom,
|
vdom,
|
||||||
&children.iter().map(|p| &p.#child_state_idents).collect(),
|
&children.iter().map(|p| &p.#child_state_idents).collect::<Vec<_>>(),
|
||||||
ctx,
|
ctx,
|
||||||
).map(|mut changed|{
|
).map(|mut changed|{
|
||||||
for id in &mut changed.node_dep{
|
for id in &mut changed.node_dep{
|
||||||
|
|
|
@ -92,6 +92,7 @@ impl NodeDepState for NodeDepCallCounter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::vec_box)]
|
||||||
#[derive(Debug, Clone, PartialEq, Default)]
|
#[derive(Debug, Clone, PartialEq, Default)]
|
||||||
struct BubbledUpStateTester(Option<String>, Vec<Box<BubbledUpStateTester>>);
|
struct BubbledUpStateTester(Option<String>, Vec<Box<BubbledUpStateTester>>);
|
||||||
impl ChildDepState for BubbledUpStateTester {
|
impl ChildDepState for BubbledUpStateTester {
|
||||||
|
|
|
@ -132,7 +132,7 @@ pub trait State: Default + Clone {
|
||||||
ty: MemberId,
|
ty: MemberId,
|
||||||
node: &'a VNode<'a>,
|
node: &'a VNode<'a>,
|
||||||
vdom: &'a dioxus_core::VirtualDom,
|
vdom: &'a dioxus_core::VirtualDom,
|
||||||
children: &Vec<&Self>,
|
children: &[&Self],
|
||||||
ctx: &AnyMap,
|
ctx: &AnyMap,
|
||||||
) -> Option<ChildStatesChanged>;
|
) -> Option<ChildStatesChanged>;
|
||||||
/// This must be a valid resolution order. (no nodes updated before a state they rely on)
|
/// This must be a valid resolution order. (no nodes updated before a state they rely on)
|
||||||
|
|
|
@ -74,7 +74,7 @@ impl NodeDepState for Focus {
|
||||||
if let Some(index) = a
|
if let Some(index) = a
|
||||||
.value
|
.value
|
||||||
.as_int32()
|
.as_int32()
|
||||||
.or(a.value.as_text().and_then(|v| v.parse::<i32>().ok()))
|
.or_else(|| a.value.as_text().and_then(|v| v.parse::<i32>().ok()))
|
||||||
{
|
{
|
||||||
match index.cmp(&0) {
|
match index.cmp(&0) {
|
||||||
Ordering::Less => FocusLevel::Unfocusable,
|
Ordering::Less => FocusLevel::Unfocusable,
|
||||||
|
|
|
@ -545,11 +545,9 @@ impl InnerInputState {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_abs_layout(node: &Node, dom: &Dom, taffy: &Taffy) -> Layout {
|
fn get_abs_layout(node: &Node, dom: &Dom, taffy: &Taffy) -> Layout {
|
||||||
let mut node_layout = taffy
|
let mut node_layout = *taffy.layout(node.state.layout.node.unwrap()).unwrap();
|
||||||
.layout(node.state.layout.node.unwrap())
|
|
||||||
.unwrap()
|
|
||||||
.clone();
|
|
||||||
let mut current = node;
|
let mut current = node;
|
||||||
|
|
||||||
while let Some(parent_id) = current.parent {
|
while let Some(parent_id) = current.parent {
|
||||||
let parent = &dom[parent_id];
|
let parent = &dom[parent_id];
|
||||||
current = parent;
|
current = parent;
|
||||||
|
|
Loading…
Reference in a new issue