Implement some clippy fixes

This commit is contained in:
Jonathan Kelley committed 2024-01-30 18:17:45 -08:00
1 parent a72c035de4
commit 09e14f1936
11 files changed
+103 -133

No files matched your search

+90 -110
View File
@@ -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 },
]
);
}