mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-22 20:23:09 +00:00
Implement some clippy fixes
This commit is contained in:
parent
a72c035de4
commit
09e14f1936
11 changed files with 103 additions and 133 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -2466,8 +2466,6 @@ name = "dioxus-core"
|
|||
version = "0.4.3"
|
||||
dependencies = [
|
||||
"dioxus",
|
||||
"dioxus-core",
|
||||
"dioxus-html",
|
||||
"dioxus-ssr",
|
||||
"futures-channel",
|
||||
"futures-util",
|
||||
|
|
|
@ -56,7 +56,7 @@ version = "0.4.3"
|
|||
|
||||
# dependencies that are shared across packages
|
||||
[workspace.dependencies]
|
||||
dioxus = { path = "packages/dioxus", version = "0.4.0", default-features = false }
|
||||
dioxus = { path = "packages/dioxus", version = "0.4.0" }
|
||||
dioxus-lib = { path = "packages/dioxus-lib", version = "0.4.0" }
|
||||
dioxus-core = { path = "packages/core", version = "0.4.2" }
|
||||
dioxus-core-macro = { path = "packages/core-macro", version = "0.4.0" }
|
||||
|
|
|
@ -25,8 +25,6 @@ serde = { version = "1", features = ["derive"], optional = true }
|
|||
[dev-dependencies]
|
||||
tokio = { workspace = true, features = ["full"] }
|
||||
dioxus = { workspace = true }
|
||||
dioxus-core = { workspace = true }
|
||||
dioxus-html = { workspace = true, features = ["serialize"] }
|
||||
pretty_assertions = "1.3.0"
|
||||
rand = "0.8.5"
|
||||
dioxus-ssr = { workspace = true }
|
||||
|
|
|
@ -738,6 +738,7 @@ impl PartialEq for AttributeValue {
|
|||
(Self::Bool(l0), Self::Bool(r0)) => l0 == r0,
|
||||
(Self::Listener(_), Self::Listener(_)) => true,
|
||||
(Self::Any(l0), Self::Any(r0)) => l0.as_ref().any_cmp(r0.as_ref()),
|
||||
(Self::None, Self::None) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use dioxus::dioxus_core::Mutation::*;
|
||||
use dioxus::dioxus_core::{AttributeValue, ElementId, NoOpMutations};
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_core::{AttributeValue, ElementId, NoOpMutations};
|
||||
|
||||
#[test]
|
||||
fn text_diff() {
|
||||
|
@ -85,119 +85,99 @@ fn element_swap() {
|
|||
|
||||
#[test]
|
||||
fn attribute_diff() {
|
||||
// fn app() -> Element {
|
||||
// let gen = cx.generation();
|
||||
fn app() -> Element {
|
||||
let gen = generation();
|
||||
|
||||
// // attributes have to be sorted by name
|
||||
// let attrs = match gen % 5 {
|
||||
// 0 => cx.bump().alloc([Attribute::new(
|
||||
// "a",
|
||||
// AttributeValue::Text("hello".into()),
|
||||
// None,
|
||||
// false,
|
||||
// )]) as &[Attribute],
|
||||
// 1 => cx.bump().alloc([
|
||||
// Attribute::new("a", AttributeValue::Text("hello".into()), None, false),
|
||||
// Attribute::new("b", AttributeValue::Text("hello".into()), None, false),
|
||||
// Attribute::new("c", AttributeValue::Text("hello".into()), None, false),
|
||||
// ]) as &[Attribute],
|
||||
// 2 => cx.bump().alloc([
|
||||
// Attribute::new("c", AttributeValue::Text("hello".into()), None, false),
|
||||
// Attribute::new("d", AttributeValue::Text("hello".into()), None, false),
|
||||
// Attribute::new("e", AttributeValue::Text("hello".into()), None, false),
|
||||
// ]) as &[Attribute],
|
||||
// 3 => cx.bump().alloc([Attribute::new(
|
||||
// "d",
|
||||
// AttributeValue::Text("world".into()),
|
||||
// None,
|
||||
// false,
|
||||
// )]) as &[Attribute],
|
||||
// _ => unreachable!(),
|
||||
// };
|
||||
// attributes have to be sorted by name
|
||||
let attrs = match gen % 5 {
|
||||
0 => vec![Attribute::new(
|
||||
"a",
|
||||
AttributeValue::Text("hello".into()),
|
||||
None,
|
||||
false,
|
||||
)],
|
||||
1 => vec![
|
||||
Attribute::new("a", AttributeValue::Text("hello".into()), None, false),
|
||||
Attribute::new("b", AttributeValue::Text("hello".into()), None, false),
|
||||
Attribute::new("c", AttributeValue::Text("hello".into()), None, false),
|
||||
],
|
||||
2 => vec![
|
||||
Attribute::new("c", AttributeValue::Text("hello".into()), None, false),
|
||||
Attribute::new("d", AttributeValue::Text("hello".into()), None, false),
|
||||
Attribute::new("e", AttributeValue::Text("hello".into()), None, false),
|
||||
],
|
||||
3 => vec![Attribute::new(
|
||||
"d",
|
||||
AttributeValue::Text("world".into()),
|
||||
None,
|
||||
false,
|
||||
)],
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
// cx.render(rsx!(
|
||||
// div {
|
||||
// ..*attrs,
|
||||
// "hello"
|
||||
// }
|
||||
// ))
|
||||
// }
|
||||
rsx!(
|
||||
div {
|
||||
..attrs,
|
||||
"hello"
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
// let mut vdom = VirtualDom::new(app);
|
||||
// _ = vdom.rebuild();
|
||||
let mut vdom = VirtualDom::new(app);
|
||||
vdom.rebuild(&mut NoOpMutations);
|
||||
|
||||
// vdom.mark_dirty(ScopeId::ROOT);
|
||||
// assert_eq!(
|
||||
// vdom.render_immediate().santize().edits,
|
||||
// [
|
||||
// SetAttribute {
|
||||
// name: "b",
|
||||
// value: (&AttributeValue::Text("hello",)).into(),
|
||||
// id: ElementId(1,),
|
||||
// ns: None,
|
||||
// },
|
||||
// SetAttribute {
|
||||
// name: "c",
|
||||
// value: (&AttributeValue::Text("hello",)).into(),
|
||||
// id: ElementId(1,),
|
||||
// ns: None,
|
||||
// },
|
||||
// ]
|
||||
// );
|
||||
vdom.mark_dirty(ScopeId::ROOT);
|
||||
assert_eq!(
|
||||
vdom.render_immediate_to_vec().santize().edits,
|
||||
[
|
||||
SetAttribute {
|
||||
name: "b",
|
||||
value: (AttributeValue::Text("hello".into())),
|
||||
id: ElementId(1,),
|
||||
ns: None,
|
||||
},
|
||||
SetAttribute {
|
||||
name: "c",
|
||||
value: (AttributeValue::Text("hello".into())),
|
||||
id: ElementId(1,),
|
||||
ns: None,
|
||||
},
|
||||
]
|
||||
);
|
||||
|
||||
// vdom.mark_dirty(ScopeId::ROOT);
|
||||
// assert_eq!(
|
||||
// vdom.render_immediate().santize().edits,
|
||||
// [
|
||||
// SetAttribute {
|
||||
// name: "a",
|
||||
// value: (&AttributeValue::None).into(),
|
||||
// id: ElementId(1,),
|
||||
// ns: None,
|
||||
// },
|
||||
// SetAttribute {
|
||||
// name: "b",
|
||||
// value: (&AttributeValue::None).into(),
|
||||
// id: ElementId(1,),
|
||||
// ns: None,
|
||||
// },
|
||||
// SetAttribute {
|
||||
// name: "d",
|
||||
// value: (&AttributeValue::Text("hello",)).into(),
|
||||
// id: ElementId(1,),
|
||||
// ns: None,
|
||||
// },
|
||||
// SetAttribute {
|
||||
// name: "e",
|
||||
// value: (&AttributeValue::Text("hello",)).into(),
|
||||
// id: ElementId(1,),
|
||||
// ns: None,
|
||||
// },
|
||||
// ]
|
||||
// );
|
||||
vdom.mark_dirty(ScopeId::ROOT);
|
||||
assert_eq!(
|
||||
vdom.render_immediate_to_vec().santize().edits,
|
||||
[
|
||||
SetAttribute { name: "a", value: AttributeValue::None, id: ElementId(1,), ns: None },
|
||||
SetAttribute { name: "b", value: AttributeValue::None, id: ElementId(1,), ns: None },
|
||||
SetAttribute {
|
||||
name: "d",
|
||||
value: AttributeValue::Text("hello".into()),
|
||||
id: ElementId(1,),
|
||||
ns: None,
|
||||
},
|
||||
SetAttribute {
|
||||
name: "e",
|
||||
value: AttributeValue::Text("hello".into()),
|
||||
id: ElementId(1,),
|
||||
ns: None,
|
||||
},
|
||||
]
|
||||
);
|
||||
|
||||
// vdom.mark_dirty(ScopeId::ROOT);
|
||||
// assert_eq!(
|
||||
// vdom.render_immediate().santize().edits,
|
||||
// [
|
||||
// SetAttribute {
|
||||
// name: "c",
|
||||
// value: (&AttributeValue::None).into(),
|
||||
// id: ElementId(1,),
|
||||
// ns: None,
|
||||
// },
|
||||
// SetAttribute {
|
||||
// name: "d",
|
||||
// value: (&AttributeValue::Text("world",)).into(),
|
||||
// id: ElementId(1,),
|
||||
// ns: None,
|
||||
// },
|
||||
// SetAttribute {
|
||||
// name: "e",
|
||||
// value: (&AttributeValue::None).into(),
|
||||
// id: ElementId(1,),
|
||||
// ns: None,
|
||||
// },
|
||||
// ]
|
||||
// );
|
||||
vdom.mark_dirty(ScopeId::ROOT);
|
||||
assert_eq!(
|
||||
vdom.render_immediate_to_vec().santize().edits,
|
||||
[
|
||||
SetAttribute { name: "c", value: AttributeValue::None, id: ElementId(1,), ns: None },
|
||||
SetAttribute {
|
||||
name: "d",
|
||||
value: AttributeValue::Text("world".into()),
|
||||
id: ElementId(1,),
|
||||
ns: None,
|
||||
},
|
||||
SetAttribute { name: "e", value: AttributeValue::None, id: ElementId(1,), ns: None },
|
||||
]
|
||||
);
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ static CLICKS: Mutex<usize> = Mutex::new(0);
|
|||
|
||||
#[test]
|
||||
fn events_propagate() {
|
||||
set_event_converter(Box::new(dioxus_html::SerializedHtmlEventConverter));
|
||||
set_event_converter(Box::new(dioxus::html::SerializedHtmlEventConverter));
|
||||
|
||||
let mut dom = VirtualDom::new(app);
|
||||
dom.rebuild(&mut dioxus_core::NoOpMutations);
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
|
||||
//! Tests for the lifecycle of components.
|
||||
use dioxus::dioxus_core::{ElementId, Mutation::*};
|
||||
use dioxus::html::SerializedHtmlEventConverter;
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_html::SerializedHtmlEventConverter;
|
||||
use std::rc::Rc;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
|
|
|
@ -94,7 +94,7 @@ async fn flushing() {
|
|||
fn app() -> Element {
|
||||
use_hook(|| {
|
||||
spawn(async move {
|
||||
for x in 0..10 {
|
||||
for _ in 0..10 {
|
||||
flush_sync().await;
|
||||
SEQUENCE.with(|s| s.borrow_mut().push(1));
|
||||
}
|
||||
|
@ -103,7 +103,7 @@ async fn flushing() {
|
|||
|
||||
use_hook(|| {
|
||||
spawn(async move {
|
||||
for x in 0..10 {
|
||||
for _ in 0..10 {
|
||||
flush_sync().await;
|
||||
SEQUENCE.with(|s| s.borrow_mut().push(2));
|
||||
}
|
||||
|
|
|
@ -97,7 +97,7 @@ where
|
|||
/// See the docs for [`use_coroutine`] for more details.
|
||||
#[must_use]
|
||||
pub fn use_coroutine_handle<M: 'static>() -> Coroutine<M> {
|
||||
use_hook(|| consume_context::<Coroutine<M>>())
|
||||
use_hook(consume_context::<Coroutine<M>>)
|
||||
}
|
||||
|
||||
#[derive(PartialEq)]
|
||||
|
@ -110,7 +110,7 @@ pub struct Coroutine<T: 'static> {
|
|||
impl<T> Coroutine<T> {
|
||||
/// Get the underlying task handle
|
||||
pub fn task(&self) -> Task {
|
||||
self.task.read().clone().unwrap()
|
||||
(*self.task.read()).unwrap()
|
||||
}
|
||||
|
||||
/// Send a message to the coroutine
|
||||
|
@ -133,12 +133,9 @@ impl<T> Coroutine<T> {
|
|||
|
||||
// manual impl since deriving doesn't work with generics
|
||||
impl<T> Copy for Coroutine<T> {}
|
||||
|
||||
impl<T> Clone for Coroutine<T> {
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
tx: self.tx,
|
||||
task: self.task,
|
||||
needs_regen: self.needs_regen,
|
||||
}
|
||||
*self
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,13 +39,9 @@ where
|
|||
|
||||
let res = future::poll_fn(|cx| {
|
||||
// Set the effect stack properly
|
||||
|
||||
// Poll the inner future
|
||||
let ready = fut.poll_unpin(cx);
|
||||
|
||||
// add any dependencies to the effect stack that we need to watch when restarting the future
|
||||
|
||||
ready
|
||||
// Poll the inner future
|
||||
fut.poll_unpin(cx)
|
||||
})
|
||||
.await;
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ where
|
|||
fn default() -> Self {
|
||||
Self {
|
||||
current: "/".parse().unwrap_or_else(|err| {
|
||||
panic!("index route does not exist:\n{}\n use MemoryHistory::with_initial_path to set a custom path", err)
|
||||
panic!("index route does not exist:\n{err}\n use MemoryHistory::with_initial_path to set a custom path")
|
||||
}),
|
||||
history: Vec::new(),
|
||||
future: Vec::new(),
|
||||
|
|
Loading…
Reference in a new issue