chore: make warnings go away
This commit is contained in:
1 parent
0027cdd938
commit
7c3d308ab5
34 files changed
+901
-810
No files matched your search
@@ -30,7 +30,7 @@ fn attrs_cycle() {
|
||||
]
|
||||
);
|
||||
|
||||
dom.mark_dirty_scope(ScopeId(0));
|
||||
dom.mark_dirty(ScopeId(0));
|
||||
assert_eq!(
|
||||
dom.render_immediate().santize().edits,
|
||||
[
|
||||
@@ -42,7 +42,7 @@ fn attrs_cycle() {
|
||||
]
|
||||
);
|
||||
|
||||
dom.mark_dirty_scope(ScopeId(0));
|
||||
dom.mark_dirty(ScopeId(0));
|
||||
assert_eq!(
|
||||
dom.render_immediate().santize().edits,
|
||||
[
|
||||
@@ -51,7 +51,7 @@ fn attrs_cycle() {
|
||||
]
|
||||
);
|
||||
|
||||
dom.mark_dirty_scope(ScopeId(0));
|
||||
dom.mark_dirty(ScopeId(0));
|
||||
assert_eq!(
|
||||
dom.render_immediate().santize().edits,
|
||||
[
|
||||
@@ -64,7 +64,7 @@ fn attrs_cycle() {
|
||||
);
|
||||
|
||||
// we take the node taken by attributes since we reused it
|
||||
dom.mark_dirty_scope(ScopeId(0));
|
||||
dom.mark_dirty(ScopeId(0));
|
||||
assert_eq!(
|
||||
dom.render_immediate().santize().edits,
|
||||
[
|
||||
|
||||
@@ -22,9 +22,7 @@ fn it_goes() {
|
||||
|
||||
let edits = dom.rebuild().santize();
|
||||
|
||||
dbg!(edits);
|
||||
|
||||
dom.mark_dirty_scope(ScopeId(0));
|
||||
dom.mark_dirty(ScopeId(0));
|
||||
|
||||
dom.render_immediate();
|
||||
}
|
||||
@@ -27,22 +27,22 @@ fn state_shares() {
|
||||
]
|
||||
);
|
||||
|
||||
dom.mark_dirty_scope(ScopeId(0));
|
||||
dom.render_immediate();
|
||||
dom.mark_dirty(ScopeId(0));
|
||||
_ = dom.render_immediate();
|
||||
assert_eq!(dom.base_scope().consume_context::<i32>().unwrap(), 1);
|
||||
|
||||
dom.mark_dirty_scope(ScopeId(0));
|
||||
dom.render_immediate();
|
||||
dom.mark_dirty(ScopeId(0));
|
||||
_ = dom.render_immediate();
|
||||
assert_eq!(dom.base_scope().consume_context::<i32>().unwrap(), 2);
|
||||
|
||||
dom.mark_dirty_scope(ScopeId(2));
|
||||
dom.mark_dirty(ScopeId(2));
|
||||
assert_eq!(
|
||||
dom.render_immediate().santize().edits,
|
||||
[SetText { value: "Value is 2", id: ElementId(1,) },]
|
||||
);
|
||||
|
||||
dom.mark_dirty_scope(ScopeId(0));
|
||||
dom.mark_dirty_scope(ScopeId(2));
|
||||
dom.mark_dirty(ScopeId(0));
|
||||
dom.mark_dirty(ScopeId(2));
|
||||
let edits = dom.render_immediate();
|
||||
assert_eq!(
|
||||
edits.santize().edits,
|
||||
|
||||
@@ -43,7 +43,7 @@ fn list_renders() {
|
||||
CreateStaticText { value: "hello world! " },
|
||||
AppendChildren { m: 1 },
|
||||
CreateElement { name: "p" },
|
||||
CreateStaticText { value: "d" },
|
||||
CreateTextPlaceholder,
|
||||
AppendChildren { m: 1 },
|
||||
AppendChildren { m: 2 },
|
||||
SaveTemplate { name: "template", m: 1 }
|
||||
|
||||
@@ -21,7 +21,7 @@ fn cycling_elements() {
|
||||
]
|
||||
);
|
||||
|
||||
dom.mark_dirty_scope(ScopeId(0));
|
||||
dom.mark_dirty(ScopeId(0));
|
||||
assert_eq!(
|
||||
dom.render_immediate().santize().edits,
|
||||
[
|
||||
@@ -31,7 +31,7 @@ fn cycling_elements() {
|
||||
);
|
||||
|
||||
// notice that the IDs cycle back to ElementId(1), preserving a minimal memory footprint
|
||||
dom.mark_dirty_scope(ScopeId(0));
|
||||
dom.mark_dirty(ScopeId(0));
|
||||
assert_eq!(
|
||||
dom.render_immediate().santize().edits,
|
||||
[
|
||||
@@ -40,7 +40,7 @@ fn cycling_elements() {
|
||||
]
|
||||
);
|
||||
|
||||
dom.mark_dirty_scope(ScopeId(0));
|
||||
dom.mark_dirty(ScopeId(0));
|
||||
assert_eq!(
|
||||
dom.render_immediate().santize().edits,
|
||||
[
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
use dioxus::core::{ElementId, Mutation::*};
|
||||
use dioxus::prelude::*;
|
||||
|
||||
/// When returning sets of components, we do a light diff of the contents to preserve some react-like functionality
|
||||
///
|
||||
/// This means that nav_bar should never get re-created and that we should only be swapping out
|
||||
/// different pointers
|
||||
#[test]
|
||||
fn component_swap() {
|
||||
fn app(cx: Scope) -> Element {
|
||||
let render_phase = cx.use_hook(|| 0);
|
||||
|
||||
*render_phase += 1;
|
||||
|
||||
cx.render(match *render_phase {
|
||||
0 => rsx! {
|
||||
nav_bar {}
|
||||
dash_board {}
|
||||
},
|
||||
1 => rsx! {
|
||||
nav_bar {}
|
||||
dash_results {}
|
||||
},
|
||||
2 => rsx! {
|
||||
nav_bar {}
|
||||
dash_board {}
|
||||
},
|
||||
3 => rsx! {
|
||||
nav_bar {}
|
||||
dash_results {}
|
||||
},
|
||||
4 => rsx! {
|
||||
nav_bar {}
|
||||
dash_board {}
|
||||
},
|
||||
_ => rsx!("blah"),
|
||||
})
|
||||
}
|
||||
|
||||
fn nav_bar(cx: Scope) -> Element {
|
||||
cx.render(rsx! {
|
||||
h1 {
|
||||
"NavBar"
|
||||
(0..3).map(|_| rsx!(nav_link {}))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn nav_link(cx: Scope) -> Element {
|
||||
cx.render(rsx!( h1 { "nav_link" } ))
|
||||
}
|
||||
|
||||
fn dash_board(cx: Scope) -> Element {
|
||||
cx.render(rsx!( div { "dashboard" } ))
|
||||
}
|
||||
|
||||
fn dash_results(cx: Scope) -> Element {
|
||||
cx.render(rsx!( div { "results" } ))
|
||||
}
|
||||
|
||||
let mut dom = VirtualDom::new(app);
|
||||
let edits = dom.rebuild().santize();
|
||||
assert_eq!(
|
||||
edits.edits,
|
||||
[
|
||||
LoadTemplate { name: "template", index: 0, id: ElementId(1) },
|
||||
LoadTemplate { name: "template", index: 0, id: ElementId(2) },
|
||||
LoadTemplate { name: "template", index: 0, id: ElementId(3) },
|
||||
LoadTemplate { name: "template", index: 0, id: ElementId(4) },
|
||||
ReplacePlaceholder { path: &[1], m: 3 },
|
||||
LoadTemplate { name: "template", index: 0, id: ElementId(5) },
|
||||
AppendChildren { m: 2 }
|
||||
]
|
||||
);
|
||||
|
||||
dom.mark_dirty(ScopeId(0));
|
||||
assert_eq!(
|
||||
dom.render_immediate().santize().edits,
|
||||
[
|
||||
LoadTemplate { name: "template", index: 0, id: ElementId(6) },
|
||||
ReplaceWith { id: ElementId(5), m: 1 }
|
||||
]
|
||||
);
|
||||
|
||||
dom.mark_dirty(ScopeId(0));
|
||||
assert_eq!(
|
||||
dom.render_immediate().santize().edits,
|
||||
[
|
||||
LoadTemplate { name: "template", index: 0, id: ElementId(5) },
|
||||
ReplaceWith { id: ElementId(6), m: 1 }
|
||||
]
|
||||
);
|
||||
|
||||
dom.mark_dirty(ScopeId(0));
|
||||
assert_eq!(
|
||||
dom.render_immediate().santize().edits,
|
||||
[
|
||||
LoadTemplate { name: "template", index: 0, id: ElementId(6) },
|
||||
ReplaceWith { id: ElementId(5), m: 1 }
|
||||
]
|
||||
);
|
||||
}
|
||||
@@ -10,21 +10,21 @@ fn text_diff() {
|
||||
}
|
||||
|
||||
let mut vdom = VirtualDom::new(app);
|
||||
vdom.rebuild();
|
||||
_ = vdom.rebuild();
|
||||
|
||||
vdom.mark_dirty_scope(ScopeId(0));
|
||||
vdom.mark_dirty(ScopeId(0));
|
||||
assert_eq!(
|
||||
vdom.render_immediate().edits,
|
||||
[SetText { value: "hello 1", id: ElementId(2) }]
|
||||
);
|
||||
|
||||
vdom.mark_dirty_scope(ScopeId(0));
|
||||
vdom.mark_dirty(ScopeId(0));
|
||||
assert_eq!(
|
||||
vdom.render_immediate().edits,
|
||||
[SetText { value: "hello 2", id: ElementId(2) }]
|
||||
);
|
||||
|
||||
vdom.mark_dirty_scope(ScopeId(0));
|
||||
vdom.mark_dirty(ScopeId(0));
|
||||
assert_eq!(
|
||||
vdom.render_immediate().edits,
|
||||
[SetText { value: "hello 3", id: ElementId(2) }]
|
||||
@@ -44,9 +44,9 @@ fn element_swap() {
|
||||
}
|
||||
|
||||
let mut vdom = VirtualDom::new(app);
|
||||
vdom.rebuild();
|
||||
_ = vdom.rebuild();
|
||||
|
||||
vdom.mark_dirty_scope(ScopeId(0));
|
||||
vdom.mark_dirty(ScopeId(0));
|
||||
assert_eq!(
|
||||
vdom.render_immediate().santize().edits,
|
||||
[
|
||||
@@ -55,7 +55,7 @@ fn element_swap() {
|
||||
]
|
||||
);
|
||||
|
||||
vdom.mark_dirty_scope(ScopeId(0));
|
||||
vdom.mark_dirty(ScopeId(0));
|
||||
assert_eq!(
|
||||
vdom.render_immediate().santize().edits,
|
||||
[
|
||||
@@ -64,7 +64,7 @@ fn element_swap() {
|
||||
]
|
||||
);
|
||||
|
||||
vdom.mark_dirty_scope(ScopeId(0));
|
||||
vdom.mark_dirty(ScopeId(0));
|
||||
assert_eq!(
|
||||
vdom.render_immediate().santize().edits,
|
||||
[
|
||||
@@ -73,7 +73,7 @@ fn element_swap() {
|
||||
]
|
||||
);
|
||||
|
||||
vdom.mark_dirty_scope(ScopeId(0));
|
||||
vdom.mark_dirty(ScopeId(0));
|
||||
assert_eq!(
|
||||
vdom.render_immediate().santize().edits,
|
||||
[
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#![allow(unused, non_upper_case_globals)]
|
||||
|
||||
//! Diffing Tests
|
||||
//!
|
||||
//! These tests only verify that the diffing algorithm works properly for single components.
|
||||
@@ -39,7 +37,7 @@ fn keyed_diffing_out_of_order() {
|
||||
]
|
||||
);
|
||||
|
||||
dom.mark_dirty_scope(ScopeId(0));
|
||||
dom.mark_dirty(ScopeId(0));
|
||||
assert_eq!(
|
||||
dom.render_immediate().edits,
|
||||
[
|
||||
@@ -64,7 +62,7 @@ fn keyed_diffing_out_of_order_adds() {
|
||||
|
||||
_ = dom.rebuild();
|
||||
|
||||
dom.mark_dirty_scope(ScopeId(0));
|
||||
dom.mark_dirty(ScopeId(0));
|
||||
assert_eq!(
|
||||
dom.render_immediate().edits,
|
||||
[
|
||||
@@ -90,7 +88,7 @@ fn keyed_diffing_out_of_order_adds_3() {
|
||||
|
||||
_ = dom.rebuild();
|
||||
|
||||
dom.mark_dirty_scope(ScopeId(0));
|
||||
dom.mark_dirty(ScopeId(0));
|
||||
assert_eq!(
|
||||
dom.render_immediate().edits,
|
||||
[
|
||||
@@ -116,7 +114,7 @@ fn keyed_diffing_out_of_order_adds_4() {
|
||||
|
||||
_ = dom.rebuild();
|
||||
|
||||
dom.mark_dirty_scope(ScopeId(0));
|
||||
dom.mark_dirty(ScopeId(0));
|
||||
assert_eq!(
|
||||
dom.render_immediate().edits,
|
||||
[
|
||||
@@ -142,7 +140,7 @@ fn keyed_diffing_out_of_order_adds_5() {
|
||||
|
||||
_ = dom.rebuild();
|
||||
|
||||
dom.mark_dirty_scope(ScopeId(0));
|
||||
dom.mark_dirty(ScopeId(0));
|
||||
assert_eq!(
|
||||
dom.render_immediate().edits,
|
||||
[
|
||||
@@ -167,7 +165,7 @@ fn keyed_diffing_additions() {
|
||||
|
||||
_ = dom.rebuild();
|
||||
|
||||
dom.mark_dirty_scope(ScopeId(0));
|
||||
dom.mark_dirty(ScopeId(0));
|
||||
assert_eq!(
|
||||
dom.render_immediate().santize().edits,
|
||||
[
|
||||
@@ -192,7 +190,7 @@ fn keyed_diffing_additions_and_moves_on_ends() {
|
||||
|
||||
_ = dom.rebuild();
|
||||
|
||||
dom.mark_dirty_scope(ScopeId(0));
|
||||
dom.mark_dirty(ScopeId(0));
|
||||
assert_eq!(
|
||||
dom.render_immediate().santize().edits,
|
||||
[
|
||||
@@ -222,7 +220,7 @@ fn keyed_diffing_additions_and_moves_in_middle() {
|
||||
_ = dom.rebuild();
|
||||
|
||||
// LIS: 4, 5, 6
|
||||
dom.mark_dirty_scope(ScopeId(0));
|
||||
dom.mark_dirty(ScopeId(0));
|
||||
assert_eq!(
|
||||
dom.render_immediate().santize().edits,
|
||||
[
|
||||
@@ -256,7 +254,7 @@ fn controlled_keyed_diffing_out_of_order() {
|
||||
_ = dom.rebuild();
|
||||
|
||||
// LIS: 5, 6
|
||||
dom.mark_dirty_scope(ScopeId(0));
|
||||
dom.mark_dirty(ScopeId(0));
|
||||
assert_eq!(
|
||||
dom.render_immediate().santize().edits,
|
||||
[
|
||||
@@ -289,7 +287,7 @@ fn controlled_keyed_diffing_out_of_order_max_test() {
|
||||
|
||||
_ = dom.rebuild();
|
||||
|
||||
dom.mark_dirty_scope(ScopeId(0));
|
||||
dom.mark_dirty(ScopeId(0));
|
||||
assert_eq!(
|
||||
dom.render_immediate().santize().edits,
|
||||
[
|
||||
@@ -318,7 +316,7 @@ fn remove_list() {
|
||||
|
||||
_ = dom.rebuild();
|
||||
|
||||
dom.mark_dirty_scope(ScopeId(0));
|
||||
dom.mark_dirty(ScopeId(0));
|
||||
assert_eq!(
|
||||
dom.render_immediate().santize().edits,
|
||||
[
|
||||
@@ -328,3 +326,31 @@ fn remove_list() {
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_common_keys() {
|
||||
let mut dom = VirtualDom::new(|cx| {
|
||||
let order: &[_] = match cx.generation() % 2 {
|
||||
0 => &[1, 2, 3],
|
||||
1 => &[4, 5, 6],
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
cx.render(rsx!(order.iter().map(|i| rsx!(div { key: "{i}" }))))
|
||||
});
|
||||
|
||||
_ = dom.rebuild();
|
||||
|
||||
dom.mark_dirty(ScopeId(0));
|
||||
assert_eq!(
|
||||
dom.render_immediate().santize().edits,
|
||||
[
|
||||
Remove { id: ElementId(2) },
|
||||
Remove { id: ElementId(3) },
|
||||
LoadTemplate { name: "template", index: 0, id: ElementId(3) },
|
||||
LoadTemplate { name: "template", index: 0, id: ElementId(2) },
|
||||
LoadTemplate { name: "template", index: 0, id: ElementId(4) },
|
||||
ReplaceWith { id: ElementId(1), m: 3 }
|
||||
]
|
||||
);
|
||||
}
|
||||
@@ -26,7 +26,7 @@ fn list_creates_one_by_one() {
|
||||
);
|
||||
|
||||
// Rendering the first item should replace the placeholder with an element
|
||||
dom.mark_dirty_scope(ScopeId(0));
|
||||
dom.mark_dirty(ScopeId(0));
|
||||
assert_eq!(
|
||||
dom.render_immediate().santize().edits,
|
||||
[
|
||||
@@ -37,7 +37,7 @@ fn list_creates_one_by_one() {
|
||||
);
|
||||
|
||||
// Rendering the next item should insert after the previous
|
||||
dom.mark_dirty_scope(ScopeId(0));
|
||||
dom.mark_dirty(ScopeId(0));
|
||||
assert_eq!(
|
||||
dom.render_immediate().santize().edits,
|
||||
[
|
||||
@@ -48,7 +48,7 @@ fn list_creates_one_by_one() {
|
||||
);
|
||||
|
||||
// ... and again!
|
||||
dom.mark_dirty_scope(ScopeId(0));
|
||||
dom.mark_dirty(ScopeId(0));
|
||||
assert_eq!(
|
||||
dom.render_immediate().santize().edits,
|
||||
[
|
||||
@@ -59,7 +59,7 @@ fn list_creates_one_by_one() {
|
||||
);
|
||||
|
||||
// once more
|
||||
dom.mark_dirty_scope(ScopeId(0));
|
||||
dom.mark_dirty(ScopeId(0));
|
||||
assert_eq!(
|
||||
dom.render_immediate().santize().edits,
|
||||
[
|
||||
@@ -106,14 +106,14 @@ fn removes_one_by_one() {
|
||||
|
||||
// Remove div(3)
|
||||
// Rendering the first item should replace the placeholder with an element
|
||||
dom.mark_dirty_scope(ScopeId(0));
|
||||
dom.mark_dirty(ScopeId(0));
|
||||
assert_eq!(
|
||||
dom.render_immediate().santize().edits,
|
||||
[Remove { id: ElementId(6) }]
|
||||
);
|
||||
|
||||
// Remove div(2)
|
||||
dom.mark_dirty_scope(ScopeId(0));
|
||||
dom.mark_dirty(ScopeId(0));
|
||||
assert_eq!(
|
||||
dom.render_immediate().santize().edits,
|
||||
[Remove { id: ElementId(4) }]
|
||||
@@ -121,7 +121,7 @@ fn removes_one_by_one() {
|
||||
|
||||
// Remove div(1) and replace with a placeholder
|
||||
// todo: this should just be a remove with no placeholder
|
||||
dom.mark_dirty_scope(ScopeId(0));
|
||||
dom.mark_dirty(ScopeId(0));
|
||||
assert_eq!(
|
||||
dom.render_immediate().santize().edits,
|
||||
[
|
||||
@@ -132,7 +132,7 @@ fn removes_one_by_one() {
|
||||
|
||||
// load the 3 and replace the placeholder
|
||||
// todo: this should actually be append to, but replace placeholder is fine for now
|
||||
dom.mark_dirty_scope(ScopeId(0));
|
||||
dom.mark_dirty(ScopeId(0));
|
||||
assert_eq!(
|
||||
dom.render_immediate().santize().edits,
|
||||
[
|
||||
@@ -169,7 +169,7 @@ fn list_shrink_multiroot() {
|
||||
]
|
||||
);
|
||||
|
||||
dom.mark_dirty_scope(ScopeId(0));
|
||||
dom.mark_dirty(ScopeId(0));
|
||||
assert_eq!(
|
||||
dom.render_immediate().santize().edits,
|
||||
[
|
||||
@@ -181,7 +181,7 @@ fn list_shrink_multiroot() {
|
||||
]
|
||||
);
|
||||
|
||||
dom.mark_dirty_scope(ScopeId(0));
|
||||
dom.mark_dirty(ScopeId(0));
|
||||
assert_eq!(
|
||||
dom.render_immediate().santize().edits,
|
||||
[
|
||||
@@ -193,7 +193,7 @@ fn list_shrink_multiroot() {
|
||||
]
|
||||
);
|
||||
|
||||
dom.mark_dirty_scope(ScopeId(0));
|
||||
dom.mark_dirty(ScopeId(0));
|
||||
assert_eq!(
|
||||
dom.render_immediate().santize().edits,
|
||||
[
|
||||
@@ -248,19 +248,19 @@ fn removes_one_by_one_multiroot() {
|
||||
]
|
||||
);
|
||||
|
||||
dom.mark_dirty_scope(ScopeId(0));
|
||||
dom.mark_dirty(ScopeId(0));
|
||||
assert_eq!(
|
||||
dom.render_immediate().santize().edits,
|
||||
[Remove { id: ElementId(10) }, Remove { id: ElementId(12) }]
|
||||
);
|
||||
|
||||
dom.mark_dirty_scope(ScopeId(0));
|
||||
dom.mark_dirty(ScopeId(0));
|
||||
assert_eq!(
|
||||
dom.render_immediate().santize().edits,
|
||||
[Remove { id: ElementId(6) }, Remove { id: ElementId(8) }]
|
||||
);
|
||||
|
||||
dom.mark_dirty_scope(ScopeId(0));
|
||||
dom.mark_dirty(ScopeId(0));
|
||||
assert_eq!(
|
||||
dom.render_immediate().santize().edits,
|
||||
[
|
||||
@@ -324,7 +324,7 @@ fn remove_many() {
|
||||
]
|
||||
);
|
||||
|
||||
dom.mark_dirty_scope(ScopeId(0));
|
||||
dom.mark_dirty(ScopeId(0));
|
||||
let edits = dom.render_immediate().santize();
|
||||
assert_eq!(
|
||||
edits.edits,
|
||||
@@ -335,7 +335,7 @@ fn remove_many() {
|
||||
]
|
||||
);
|
||||
|
||||
dom.mark_dirty_scope(ScopeId(0));
|
||||
dom.mark_dirty(ScopeId(0));
|
||||
let edits = dom.render_immediate().santize();
|
||||
assert_eq!(
|
||||
edits.edits,
|
||||
@@ -352,7 +352,7 @@ fn remove_many() {
|
||||
]
|
||||
);
|
||||
|
||||
dom.mark_dirty_scope(ScopeId(0));
|
||||
dom.mark_dirty(ScopeId(0));
|
||||
let edits = dom.render_immediate().santize();
|
||||
assert_eq!(
|
||||
edits.edits,
|
||||
@@ -366,7 +366,7 @@ fn remove_many() {
|
||||
]
|
||||
);
|
||||
|
||||
dom.mark_dirty_scope(ScopeId(0));
|
||||
dom.mark_dirty(ScopeId(0));
|
||||
let edits = dom.render_immediate().santize();
|
||||
assert_eq!(
|
||||
edits.edits,
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
//! It should be possible to swap out templates at runtime, enabling hotreloading
|
||||
@@ -44,10 +44,7 @@ fn events_generate() {
|
||||
|
||||
match *count {
|
||||
0 => cx.render(rsx! {
|
||||
div {
|
||||
onclick: move |_| {
|
||||
*count += 1
|
||||
},
|
||||
div { onclick: move |_| *count += 1,
|
||||
div { "nested" }
|
||||
"Click me!"
|
||||
}
|
||||
@@ -59,15 +56,9 @@ fn events_generate() {
|
||||
let mut dom = VirtualDom::new(app);
|
||||
_ = dom.rebuild();
|
||||
|
||||
dom.handle_event(
|
||||
"click",
|
||||
Rc::new(MouseData::default()),
|
||||
ElementId(1),
|
||||
true,
|
||||
EventPriority::Immediate,
|
||||
);
|
||||
dom.handle_event("click", Rc::new(MouseData::default()), ElementId(1), true);
|
||||
|
||||
dom.mark_dirty_scope(ScopeId(0));
|
||||
dom.mark_dirty(ScopeId(0));
|
||||
let edits = dom.render_immediate();
|
||||
|
||||
assert_eq!(
|
||||
@@ -175,95 +166,3 @@ fn events_generate() {
|
||||
// ]
|
||||
// );
|
||||
// }
|
||||
|
||||
// #[test]
|
||||
// fn component_swap() {
|
||||
// fn app(cx: Scope) -> Element {
|
||||
// let render_phase = cx.use_hook(|| 0);
|
||||
// *render_phase += 1;
|
||||
|
||||
// cx.render(match *render_phase {
|
||||
// 0 => rsx_without_templates!(
|
||||
// div {
|
||||
// NavBar {}
|
||||
// Dashboard {}
|
||||
// }
|
||||
// ),
|
||||
// 1 => rsx_without_templates!(
|
||||
// div {
|
||||
// NavBar {}
|
||||
// Results {}
|
||||
// }
|
||||
// ),
|
||||
// 2 => rsx_without_templates!(
|
||||
// div {
|
||||
// NavBar {}
|
||||
// Dashboard {}
|
||||
// }
|
||||
// ),
|
||||
// 3 => rsx_without_templates!(
|
||||
// div {
|
||||
// NavBar {}
|
||||
// Results {}
|
||||
// }
|
||||
// ),
|
||||
// 4 => rsx_without_templates!(
|
||||
// div {
|
||||
// NavBar {}
|
||||
// Dashboard {}
|
||||
// }
|
||||
// ),
|
||||
// _ => rsx_without_templates!("blah"),
|
||||
// })
|
||||
// };
|
||||
|
||||
// static NavBar: Component = |cx| {
|
||||
// println!("running navbar");
|
||||
// cx.render(rsx_without_templates! {
|
||||
// h1 {
|
||||
// "NavBar"
|
||||
// {(0..3).map(|f| rsx_without_templates!(NavLink {}))}
|
||||
// }
|
||||
// })
|
||||
// };
|
||||
|
||||
// static NavLink: Component = |cx| {
|
||||
// println!("running navlink");
|
||||
// cx.render(rsx_without_templates! {
|
||||
// h1 {
|
||||
// "NavLink"
|
||||
// }
|
||||
// })
|
||||
// };
|
||||
|
||||
// static Dashboard: Component = |cx| {
|
||||
// println!("running dashboard");
|
||||
// cx.render(rsx_without_templates! {
|
||||
// div {
|
||||
// "dashboard"
|
||||
// }
|
||||
// })
|
||||
// };
|
||||
|
||||
// static Results: Component = |cx| {
|
||||
// println!("running results");
|
||||
// cx.render(rsx_without_templates! {
|
||||
// div {
|
||||
// "results"
|
||||
// }
|
||||
// })
|
||||
// };
|
||||
|
||||
// let mut dom = VirtualDom::new(app);
|
||||
// let edits = dom.rebuild();
|
||||
// dbg!(&edits);
|
||||
|
||||
// let edits = dom.work_with_deadline(|| false);
|
||||
// dbg!(&edits);
|
||||
// let edits = dom.work_with_deadline(|| false);
|
||||
// dbg!(&edits);
|
||||
// let edits = dom.work_with_deadline(|| false);
|
||||
// dbg!(&edits);
|
||||
// let edits = dom.work_with_deadline(|| false);
|
||||
// dbg!(&edits);
|
||||
// }
|
||||
@@ -0,0 +1,127 @@
|
||||
use dioxus::prelude::*;
|
||||
|
||||
#[test]
|
||||
fn app_drops() {
|
||||
fn app(cx: Scope) -> Element {
|
||||
cx.render(rsx! {
|
||||
div {}
|
||||
})
|
||||
}
|
||||
|
||||
let mut dom = VirtualDom::new(app);
|
||||
|
||||
_ = dom.rebuild();
|
||||
dom.mark_dirty(ScopeId(0));
|
||||
_ = dom.render_immediate();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hooks_drop() {
|
||||
fn app(cx: Scope) -> Element {
|
||||
cx.use_hook(|| String::from("asd"));
|
||||
cx.use_hook(|| String::from("asd"));
|
||||
cx.use_hook(|| String::from("asd"));
|
||||
cx.use_hook(|| String::from("asd"));
|
||||
|
||||
cx.render(rsx! {
|
||||
div {}
|
||||
})
|
||||
}
|
||||
|
||||
let mut dom = VirtualDom::new(app);
|
||||
|
||||
_ = dom.rebuild();
|
||||
dom.mark_dirty(ScopeId(0));
|
||||
_ = dom.render_immediate();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn contexts_drop() {
|
||||
fn app(cx: Scope) -> Element {
|
||||
cx.provide_context(String::from("asd"));
|
||||
|
||||
cx.render(rsx! {
|
||||
div {
|
||||
child_comp {}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn child_comp(cx: Scope) -> Element {
|
||||
let el = cx.consume_context::<String>().unwrap();
|
||||
|
||||
cx.render(rsx! {
|
||||
div { "hello {el}" }
|
||||
})
|
||||
}
|
||||
|
||||
let mut dom = VirtualDom::new(app);
|
||||
|
||||
_ = dom.rebuild();
|
||||
dom.mark_dirty(ScopeId(0));
|
||||
_ = dom.render_immediate();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tasks_drop() {
|
||||
fn app(cx: Scope) -> Element {
|
||||
cx.spawn(async {
|
||||
tokio::time::sleep(std::time::Duration::from_millis(100000)).await;
|
||||
});
|
||||
|
||||
cx.render(rsx! {
|
||||
div { }
|
||||
})
|
||||
}
|
||||
|
||||
let mut dom = VirtualDom::new(app);
|
||||
|
||||
_ = dom.rebuild();
|
||||
dom.mark_dirty(ScopeId(0));
|
||||
_ = dom.render_immediate();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn root_props_drop() {
|
||||
struct RootProps(String);
|
||||
|
||||
let mut dom = VirtualDom::new_with_props(
|
||||
|cx| cx.render(rsx!( div { "{cx.props.0}" } )),
|
||||
RootProps("asdasd".to_string()),
|
||||
);
|
||||
|
||||
_ = dom.rebuild();
|
||||
dom.mark_dirty(ScopeId(0));
|
||||
_ = dom.render_immediate();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn diffing_drops_old() {
|
||||
fn app(cx: Scope) -> Element {
|
||||
cx.render(rsx! {
|
||||
div {
|
||||
match cx.generation() % 2 {
|
||||
0 => rsx!( child_comp1 { name: "asdasd".to_string() }),
|
||||
1 => rsx!( child_comp2 { name: "asdasd".to_string() }),
|
||||
_ => todo!()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
#[inline_props]
|
||||
fn child_comp1(cx: Scope, name: String) -> Element {
|
||||
cx.render(rsx! { "Hello {name}" })
|
||||
}
|
||||
|
||||
#[inline_props]
|
||||
fn child_comp2(cx: Scope, name: String) -> Element {
|
||||
cx.render(rsx! { "Goodbye {name}" })
|
||||
}
|
||||
|
||||
let mut dom = VirtualDom::new(app);
|
||||
_ = dom.rebuild();
|
||||
dom.mark_dirty(ScopeId(0));
|
||||
|
||||
_ = dom.render_immediate();
|
||||
}
|
||||
+244
-301
@@ -1,32 +1,28 @@
|
||||
#![allow(non_snake_case)]
|
||||
/*
|
||||
Stress Miri as much as possible.
|
||||
|
||||
Prove that we don't leak memory and that our methods are safe.
|
||||
|
||||
Specifically:
|
||||
- [ ] VirtualDom drops memory safely
|
||||
- [ ] Borrowed components don't expose invalid pointers
|
||||
- [ ] Async isn't busted
|
||||
*/
|
||||
use std::rc::Rc;
|
||||
|
||||
use dioxus::prelude::*;
|
||||
|
||||
/// This test ensures that if a component aborts early, it is replaced with a placeholder.
|
||||
/// In debug, this should also toss a warning.
|
||||
/// This test checks that we should release all memory used by the virtualdom when it exits.
|
||||
///
|
||||
/// When miri runs, it'll let us know if we leaked or aliased.
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn test_memory_leak() {
|
||||
fn app(cx: Scope) -> Element {
|
||||
let val = cx.use_hook(|| 0);
|
||||
let val = cx.generation();
|
||||
|
||||
*val += 1;
|
||||
cx.spawn(async {
|
||||
tokio::time::sleep(std::time::Duration::from_millis(100000)).await;
|
||||
});
|
||||
|
||||
if *val == 2 || *val == 4 {
|
||||
if val == 2 || val == 4 {
|
||||
return cx.render(rsx!(()));
|
||||
}
|
||||
|
||||
let name = cx.use_hook(|| String::from("asd"));
|
||||
let name = cx.use_hook(|| String::from("numbers: "));
|
||||
|
||||
name.push_str("123 ");
|
||||
|
||||
cx.render(rsx!(
|
||||
div { "Hello, world!" }
|
||||
@@ -36,24 +32,26 @@ fn test_memory_leak() {
|
||||
Child {}
|
||||
Child {}
|
||||
Child {}
|
||||
BorrowedChild { na: name }
|
||||
BorrowedChild { na: name }
|
||||
BorrowedChild { na: name }
|
||||
BorrowedChild { na: name }
|
||||
BorrowedChild { na: name }
|
||||
BorrowedChild { name: name }
|
||||
BorrowedChild { name: name }
|
||||
BorrowedChild { name: name }
|
||||
BorrowedChild { name: name }
|
||||
BorrowedChild { name: name }
|
||||
))
|
||||
}
|
||||
|
||||
#[derive(Props)]
|
||||
struct BorrowedProps<'a> {
|
||||
na: &'a str,
|
||||
name: &'a str,
|
||||
}
|
||||
|
||||
fn BorrowedChild<'a>(cx: Scope<'a, BorrowedProps<'a>>) -> Element {
|
||||
render!(div {
|
||||
"goodbye {cx.props.na}"
|
||||
Child {}
|
||||
Child {}
|
||||
cx.render(rsx! {
|
||||
div {
|
||||
"goodbye {cx.props.name}"
|
||||
Child {}
|
||||
Child {}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -63,24 +61,21 @@ fn test_memory_leak() {
|
||||
|
||||
let mut dom = VirtualDom::new(app);
|
||||
|
||||
dom.rebuild();
|
||||
dom.hard_diff(ScopeId(0));
|
||||
dom.hard_diff(ScopeId(0));
|
||||
dom.hard_diff(ScopeId(0));
|
||||
dom.hard_diff(ScopeId(0));
|
||||
dom.hard_diff(ScopeId(0));
|
||||
dom.hard_diff(ScopeId(0));
|
||||
_ = dom.rebuild();
|
||||
|
||||
for _ in 0..5 {
|
||||
dom.mark_dirty(ScopeId(0));
|
||||
_ = dom.render_immediate();
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn memo_works_properly() {
|
||||
fn app(cx: Scope) -> Element {
|
||||
let val = cx.use_hook(|| 0);
|
||||
let val = cx.generation();
|
||||
|
||||
*val += 1;
|
||||
|
||||
if *val == 2 || *val == 4 {
|
||||
return None;
|
||||
if val == 2 || val == 4 {
|
||||
return cx.render(rsx!(()));
|
||||
}
|
||||
|
||||
let name = cx.use_hook(|| String::from("asd"));
|
||||
@@ -100,309 +95,257 @@ fn memo_works_properly() {
|
||||
render!(div { "goodbye world" })
|
||||
}
|
||||
|
||||
let mut dom = new_dom(app, ());
|
||||
let mut dom = VirtualDom::new(app);
|
||||
|
||||
dom.rebuild();
|
||||
dom.hard_diff(ScopeId(0));
|
||||
dom.hard_diff(ScopeId(0));
|
||||
dom.hard_diff(ScopeId(0));
|
||||
dom.hard_diff(ScopeId(0));
|
||||
dom.hard_diff(ScopeId(0));
|
||||
dom.hard_diff(ScopeId(0));
|
||||
dom.hard_diff(ScopeId(0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn free_works_on_root_props() {
|
||||
fn app(cx: Scope<Custom>) -> Element {
|
||||
cx.render(rsx! {
|
||||
Child { a: "alpha"}
|
||||
Child { a: "beta"}
|
||||
Child { a: "gamma"}
|
||||
Child { a: "delta"}
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(Props, PartialEq)]
|
||||
struct ChildProps {
|
||||
a: &'static str,
|
||||
}
|
||||
|
||||
fn Child(cx: Scope<ChildProps>) -> Element {
|
||||
render!("child {cx.props.a}")
|
||||
}
|
||||
|
||||
struct Custom {
|
||||
val: String,
|
||||
}
|
||||
|
||||
impl Drop for Custom {
|
||||
fn drop(&mut self) {
|
||||
dbg!("dropped! {}", &self.val);
|
||||
}
|
||||
}
|
||||
|
||||
let mut dom = new_dom(app, Custom { val: String::from("asd") });
|
||||
dom.rebuild();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn free_works_on_borrowed() {
|
||||
fn app(cx: Scope) -> Element {
|
||||
cx.render(rsx! {
|
||||
Child { a: "alpha", b: "asd".to_string() }
|
||||
})
|
||||
}
|
||||
#[derive(Props)]
|
||||
struct ChildProps<'a> {
|
||||
a: &'a str,
|
||||
b: String,
|
||||
}
|
||||
|
||||
fn Child<'a>(cx: Scope<'a, ChildProps<'a>>) -> Element {
|
||||
dbg!("rendering child");
|
||||
render!("child {cx.props.a}, {cx.props.b}")
|
||||
}
|
||||
|
||||
impl Drop for ChildProps<'_> {
|
||||
fn drop(&mut self) {
|
||||
dbg!("dropped child!");
|
||||
}
|
||||
}
|
||||
|
||||
let mut dom = new_dom(app, ());
|
||||
let _ = dom.rebuild();
|
||||
todo!()
|
||||
// dom.hard_diff(ScopeId(0));
|
||||
// dom.hard_diff(ScopeId(0));
|
||||
// dom.hard_diff(ScopeId(0));
|
||||
// dom.hard_diff(ScopeId(0));
|
||||
// dom.hard_diff(ScopeId(0));
|
||||
// dom.hard_diff(ScopeId(0));
|
||||
// dom.hard_diff(ScopeId(0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn free_works_on_root_hooks() {
|
||||
/*
|
||||
On Drop, scopearena drops all the hook contents.
|
||||
On Drop, scopearena drops all the hook contents. and props
|
||||
*/
|
||||
|
||||
struct Droppable<T>(T);
|
||||
impl<T> Drop for Droppable<T> {
|
||||
fn drop(&mut self) {
|
||||
dbg!("dropping droppable");
|
||||
}
|
||||
#[derive(PartialEq, Clone, Props)]
|
||||
struct AppProps {
|
||||
inner: Rc<String>,
|
||||
}
|
||||
|
||||
fn app(cx: Scope) -> Element {
|
||||
let name = cx.use_hook(|| Droppable(String::from("asd")));
|
||||
render!(div { "{name.0}" })
|
||||
fn app(cx: Scope<AppProps>) -> Element {
|
||||
let name: &AppProps = cx.use_hook(|| cx.props.clone());
|
||||
render!(child_component { inner: name.inner.clone() })
|
||||
}
|
||||
|
||||
let mut dom = new_dom(app, ());
|
||||
let _ = dom.rebuild();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn old_props_arent_stale() {
|
||||
fn app(cx: Scope) -> Element {
|
||||
dbg!("rendering parent");
|
||||
let cnt = cx.use_hook(|| 0);
|
||||
*cnt += 1;
|
||||
|
||||
if *cnt == 1 {
|
||||
render!(div { Child { a: "abcdef".to_string() } })
|
||||
} else {
|
||||
render!(div { Child { a: "abcdef".to_string() } })
|
||||
}
|
||||
fn child_component(cx: Scope<AppProps>) -> Element {
|
||||
render!(div { "{cx.props.inner}" })
|
||||
}
|
||||
|
||||
#[derive(Props, PartialEq)]
|
||||
struct ChildProps {
|
||||
a: String,
|
||||
}
|
||||
fn Child(cx: Scope<ChildProps>) -> Element {
|
||||
dbg!("rendering child", &cx.props.a);
|
||||
render!(div { "child {cx.props.a}" })
|
||||
}
|
||||
|
||||
let mut dom = new_dom(app, ());
|
||||
let ptr = Rc::new("asdasd".to_string());
|
||||
let mut dom = VirtualDom::new_with_props(app, AppProps { inner: ptr.clone() });
|
||||
let _ = dom.rebuild();
|
||||
|
||||
dom.handle_message(SchedulerMsg::Immediate(ScopeId(0)));
|
||||
dom.work_with_deadline(|| false);
|
||||
// ptr gets cloned into props and then into the hook
|
||||
assert_eq!(Rc::strong_count(&ptr), 4);
|
||||
|
||||
dom.handle_message(SchedulerMsg::Immediate(ScopeId(0)));
|
||||
dom.work_with_deadline(|| false);
|
||||
drop(dom);
|
||||
|
||||
dom.handle_message(SchedulerMsg::Immediate(ScopeId(0)));
|
||||
dom.work_with_deadline(|| false);
|
||||
|
||||
dbg!("forcing update to child");
|
||||
|
||||
dom.handle_message(SchedulerMsg::Immediate(ScopeId(1)));
|
||||
dom.work_with_deadline(|| false);
|
||||
|
||||
dom.handle_message(SchedulerMsg::Immediate(ScopeId(1)));
|
||||
dom.work_with_deadline(|| false);
|
||||
|
||||
dom.handle_message(SchedulerMsg::Immediate(ScopeId(1)));
|
||||
dom.work_with_deadline(|| false);
|
||||
assert_eq!(Rc::strong_count(&ptr), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn basic() {
|
||||
fn app(cx: Scope) -> Element {
|
||||
render!(div {
|
||||
Child { a: "abcdef".to_string() }
|
||||
})
|
||||
}
|
||||
// #[test]
|
||||
// fn old_props_arent_stale() {
|
||||
// fn app(cx: Scope) -> Element {
|
||||
// dbg!("rendering parent");
|
||||
// let cnt = cx.use_hook(|| 0);
|
||||
// *cnt += 1;
|
||||
|
||||
#[derive(Props, PartialEq)]
|
||||
struct ChildProps {
|
||||
a: String,
|
||||
}
|
||||
// if *cnt == 1 {
|
||||
// render!(div { Child { a: "abcdef".to_string() } })
|
||||
// } else {
|
||||
// render!(div { Child { a: "abcdef".to_string() } })
|
||||
// }
|
||||
// }
|
||||
|
||||
fn Child(cx: Scope<ChildProps>) -> Element {
|
||||
dbg!("rendering child", &cx.props.a);
|
||||
render!(div { "child {cx.props.a}" })
|
||||
}
|
||||
// #[derive(Props, PartialEq)]
|
||||
// struct ChildProps {
|
||||
// a: String,
|
||||
// }
|
||||
// fn Child(cx: Scope<ChildProps>) -> Element {
|
||||
// dbg!("rendering child", &cx.props.a);
|
||||
// render!(div { "child {cx.props.a}" })
|
||||
// }
|
||||
|
||||
let mut dom = new_dom(app, ());
|
||||
let _ = dom.rebuild();
|
||||
// let mut dom = new_dom(app, ());
|
||||
// let _ = dom.rebuild();
|
||||
|
||||
dom.handle_message(SchedulerMsg::Immediate(ScopeId(0)));
|
||||
dom.work_with_deadline(|| false);
|
||||
// dom.handle_message(SchedulerMsg::Immediate(ScopeId(0)));
|
||||
// dom.work_with_deadline(|| false);
|
||||
|
||||
dom.handle_message(SchedulerMsg::Immediate(ScopeId(0)));
|
||||
dom.work_with_deadline(|| false);
|
||||
}
|
||||
// dom.handle_message(SchedulerMsg::Immediate(ScopeId(0)));
|
||||
// dom.work_with_deadline(|| false);
|
||||
|
||||
#[test]
|
||||
fn leak_thru_children() {
|
||||
fn app(cx: Scope) -> Element {
|
||||
cx.render(rsx! {
|
||||
Child {
|
||||
name: "asd".to_string(),
|
||||
}
|
||||
});
|
||||
cx.render(rsx! {
|
||||
div {}
|
||||
})
|
||||
}
|
||||
// dom.handle_message(SchedulerMsg::Immediate(ScopeId(0)));
|
||||
// dom.work_with_deadline(|| false);
|
||||
|
||||
#[inline_props]
|
||||
fn Child(cx: Scope, name: String) -> Element {
|
||||
render!(div { "child {name}" })
|
||||
}
|
||||
// dbg!("forcing update to child");
|
||||
|
||||
let mut dom = new_dom(app, ());
|
||||
let _ = dom.rebuild();
|
||||
// dom.handle_message(SchedulerMsg::Immediate(ScopeId(1)));
|
||||
// dom.work_with_deadline(|| false);
|
||||
|
||||
dom.handle_message(SchedulerMsg::Immediate(ScopeId(0)));
|
||||
dom.work_with_deadline(|| false);
|
||||
// dom.handle_message(SchedulerMsg::Immediate(ScopeId(1)));
|
||||
// dom.work_with_deadline(|| false);
|
||||
|
||||
dom.handle_message(SchedulerMsg::Immediate(ScopeId(0)));
|
||||
dom.work_with_deadline(|| false);
|
||||
}
|
||||
// dom.handle_message(SchedulerMsg::Immediate(ScopeId(1)));
|
||||
// dom.work_with_deadline(|| false);
|
||||
// }
|
||||
|
||||
#[test]
|
||||
fn test_pass_thru() {
|
||||
#[inline_props]
|
||||
fn NavContainer<'a>(cx: Scope, children: Element<'a>) -> Element {
|
||||
cx.render(rsx! {
|
||||
header {
|
||||
nav { children }
|
||||
}
|
||||
})
|
||||
}
|
||||
// #[test]
|
||||
// fn basic() {
|
||||
// fn app(cx: Scope) -> Element {
|
||||
// render!(div {
|
||||
// Child { a: "abcdef".to_string() }
|
||||
// })
|
||||
// }
|
||||
|
||||
fn NavMenu(cx: Scope) -> Element {
|
||||
render!( NavBrand {}
|
||||
div {
|
||||
NavStart {}
|
||||
NavEnd {}
|
||||
}
|
||||
)
|
||||
}
|
||||
// #[derive(Props, PartialEq)]
|
||||
// struct ChildProps {
|
||||
// a: String,
|
||||
// }
|
||||
|
||||
fn NavBrand(cx: Scope) -> Element {
|
||||
render!(div {})
|
||||
}
|
||||
// fn Child(cx: Scope<ChildProps>) -> Element {
|
||||
// dbg!("rendering child", &cx.props.a);
|
||||
// render!(div { "child {cx.props.a}" })
|
||||
// }
|
||||
|
||||
fn NavStart(cx: Scope) -> Element {
|
||||
render!(div {})
|
||||
}
|
||||
// let mut dom = new_dom(app, ());
|
||||
// let _ = dom.rebuild();
|
||||
|
||||
fn NavEnd(cx: Scope) -> Element {
|
||||
render!(div {})
|
||||
}
|
||||
// dom.handle_message(SchedulerMsg::Immediate(ScopeId(0)));
|
||||
// dom.work_with_deadline(|| false);
|
||||
|
||||
#[inline_props]
|
||||
fn MainContainer<'a>(
|
||||
cx: Scope,
|
||||
nav: Element<'a>,
|
||||
body: Element<'a>,
|
||||
footer: Element<'a>,
|
||||
) -> Element {
|
||||
cx.render(rsx! {
|
||||
div {
|
||||
class: "columns is-mobile",
|
||||
div {
|
||||
class: "column is-full",
|
||||
nav,
|
||||
body,
|
||||
footer,
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
// dom.handle_message(SchedulerMsg::Immediate(ScopeId(0)));
|
||||
// dom.work_with_deadline(|| false);
|
||||
// }
|
||||
|
||||
fn app(cx: Scope) -> Element {
|
||||
let nav = cx.render(rsx! {
|
||||
NavContainer {
|
||||
NavMenu {}
|
||||
}
|
||||
});
|
||||
let body = cx.render(rsx! {
|
||||
div {}
|
||||
});
|
||||
let footer = cx.render(rsx! {
|
||||
div {}
|
||||
});
|
||||
// #[test]
|
||||
// fn leak_thru_children() {
|
||||
// fn app(cx: Scope) -> Element {
|
||||
// cx.render(rsx! {
|
||||
// Child {
|
||||
// name: "asd".to_string(),
|
||||
// }
|
||||
// });
|
||||
// cx.render(rsx! {
|
||||
// div {}
|
||||
// })
|
||||
// }
|
||||
|
||||
cx.render(rsx! {
|
||||
MainContainer {
|
||||
nav: nav,
|
||||
body: body,
|
||||
footer: footer,
|
||||
}
|
||||
})
|
||||
}
|
||||
// #[inline_props]
|
||||
// fn Child(cx: Scope, name: String) -> Element {
|
||||
// render!(div { "child {name}" })
|
||||
// }
|
||||
|
||||
let mut dom = new_dom(app, ());
|
||||
let _ = dom.rebuild();
|
||||
// let mut dom = new_dom(app, ());
|
||||
// let _ = dom.rebuild();
|
||||
|
||||
for _ in 0..40 {
|
||||
dom.handle_message(SchedulerMsg::Immediate(ScopeId(0)));
|
||||
dom.work_with_deadline(|| false);
|
||||
dom.handle_message(SchedulerMsg::Immediate(ScopeId(0)));
|
||||
dom.work_with_deadline(|| false);
|
||||
dom.handle_message(SchedulerMsg::Immediate(ScopeId(0)));
|
||||
dom.work_with_deadline(|| false);
|
||||
// dom.handle_message(SchedulerMsg::Immediate(ScopeId(0)));
|
||||
// dom.work_with_deadline(|| false);
|
||||
|
||||
dom.handle_message(SchedulerMsg::Immediate(ScopeId(1)));
|
||||
dom.work_with_deadline(|| false);
|
||||
dom.handle_message(SchedulerMsg::Immediate(ScopeId(1)));
|
||||
dom.work_with_deadline(|| false);
|
||||
dom.handle_message(SchedulerMsg::Immediate(ScopeId(1)));
|
||||
dom.work_with_deadline(|| false);
|
||||
// dom.handle_message(SchedulerMsg::Immediate(ScopeId(0)));
|
||||
// dom.work_with_deadline(|| false);
|
||||
// }
|
||||
|
||||
dom.handle_message(SchedulerMsg::Immediate(ScopeId(2)));
|
||||
dom.work_with_deadline(|| false);
|
||||
dom.handle_message(SchedulerMsg::Immediate(ScopeId(2)));
|
||||
dom.work_with_deadline(|| false);
|
||||
dom.handle_message(SchedulerMsg::Immediate(ScopeId(2)));
|
||||
dom.work_with_deadline(|| false);
|
||||
// #[test]
|
||||
// fn test_pass_thru() {
|
||||
// #[inline_props]
|
||||
// fn NavContainer<'a>(cx: Scope, children: Element<'a>) -> Element {
|
||||
// cx.render(rsx! {
|
||||
// header {
|
||||
// nav { children }
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
|
||||
dom.handle_message(SchedulerMsg::Immediate(ScopeId(3)));
|
||||
dom.work_with_deadline(|| false);
|
||||
dom.handle_message(SchedulerMsg::Immediate(ScopeId(3)));
|
||||
dom.work_with_deadline(|| false);
|
||||
dom.handle_message(SchedulerMsg::Immediate(ScopeId(3)));
|
||||
dom.work_with_deadline(|| false);
|
||||
}
|
||||
}
|
||||
// fn NavMenu(cx: Scope) -> Element {
|
||||
// render!( NavBrand {}
|
||||
// div {
|
||||
// NavStart {}
|
||||
// NavEnd {}
|
||||
// }
|
||||
// )
|
||||
// }
|
||||
|
||||
// fn NavBrand(cx: Scope) -> Element {
|
||||
// render!(div {})
|
||||
// }
|
||||
|
||||
// fn NavStart(cx: Scope) -> Element {
|
||||
// render!(div {})
|
||||
// }
|
||||
|
||||
// fn NavEnd(cx: Scope) -> Element {
|
||||
// render!(div {})
|
||||
// }
|
||||
|
||||
// #[inline_props]
|
||||
// fn MainContainer<'a>(
|
||||
// cx: Scope,
|
||||
// nav: Element<'a>,
|
||||
// body: Element<'a>,
|
||||
// footer: Element<'a>,
|
||||
// ) -> Element {
|
||||
// cx.render(rsx! {
|
||||
// div {
|
||||
// class: "columns is-mobile",
|
||||
// div {
|
||||
// class: "column is-full",
|
||||
// nav,
|
||||
// body,
|
||||
// footer,
|
||||
// }
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
|
||||
// fn app(cx: Scope) -> Element {
|
||||
// let nav = cx.render(rsx! {
|
||||
// NavContainer {
|
||||
// NavMenu {}
|
||||
// }
|
||||
// });
|
||||
// let body = cx.render(rsx! {
|
||||
// div {}
|
||||
// });
|
||||
// let footer = cx.render(rsx! {
|
||||
// div {}
|
||||
// });
|
||||
|
||||
// cx.render(rsx! {
|
||||
// MainContainer {
|
||||
// nav: nav,
|
||||
// body: body,
|
||||
// footer: footer,
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
|
||||
// let mut dom = new_dom(app, ());
|
||||
// let _ = dom.rebuild();
|
||||
|
||||
// for _ in 0..40 {
|
||||
// dom.handle_message(SchedulerMsg::Immediate(ScopeId(0)));
|
||||
// dom.work_with_deadline(|| false);
|
||||
// dom.handle_message(SchedulerMsg::Immediate(ScopeId(0)));
|
||||
// dom.work_with_deadline(|| false);
|
||||
// dom.handle_message(SchedulerMsg::Immediate(ScopeId(0)));
|
||||
// dom.work_with_deadline(|| false);
|
||||
|
||||
// dom.handle_message(SchedulerMsg::Immediate(ScopeId(1)));
|
||||
// dom.work_with_deadline(|| false);
|
||||
// dom.handle_message(SchedulerMsg::Immediate(ScopeId(1)));
|
||||
// dom.work_with_deadline(|| false);
|
||||
// dom.handle_message(SchedulerMsg::Immediate(ScopeId(1)));
|
||||
// dom.work_with_deadline(|| false);
|
||||
|
||||
// dom.handle_message(SchedulerMsg::Immediate(ScopeId(2)));
|
||||
// dom.work_with_deadline(|| false);
|
||||
// dom.handle_message(SchedulerMsg::Immediate(ScopeId(2)));
|
||||
// dom.work_with_deadline(|| false);
|
||||
// dom.handle_message(SchedulerMsg::Immediate(ScopeId(2)));
|
||||
// dom.work_with_deadline(|| false);
|
||||
|
||||
// dom.handle_message(SchedulerMsg::Immediate(ScopeId(3)));
|
||||
// dom.work_with_deadline(|| false);
|
||||
// dom.handle_message(SchedulerMsg::Immediate(ScopeId(3)));
|
||||
// dom.work_with_deadline(|| false);
|
||||
// dom.handle_message(SchedulerMsg::Immediate(ScopeId(3)));
|
||||
// dom.work_with_deadline(|| false);
|
||||
// }
|
||||
// }
|
||||
@@ -13,10 +13,6 @@ fn root_node_isnt_null() {
|
||||
// We haven't built the tree, so trying to get out the root node should fail
|
||||
assert!(scope.try_root_node().is_none());
|
||||
|
||||
// There should be no way to gain an invalid pointer
|
||||
assert!(scope.current_frame().node.get().is_null());
|
||||
assert!(scope.previous_frame().node.get().is_null());
|
||||
|
||||
// The height should be 0
|
||||
assert_eq!(scope.height(), 0);
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ async fn it_works() {
|
||||
|
||||
let mutations = dom.rebuild().santize();
|
||||
|
||||
// We should at least get the top-level template in
|
||||
// We should at least get the top-level template in before pausing for the children
|
||||
assert_eq!(
|
||||
mutations.template_mutations,
|
||||
[
|
||||
|
||||
@@ -13,7 +13,7 @@ async fn it_works() {
|
||||
|
||||
tokio::select! {
|
||||
_ = dom.wait_for_work() => {}
|
||||
_ = tokio::time::sleep(Duration::from_millis(10)) => {}
|
||||
_ = tokio::time::sleep(Duration::from_millis(500)) => {}
|
||||
};
|
||||
|
||||
// By the time the tasks are finished, we should've accumulated ticks from two tasks
|
||||
|
||||
Reference in new issue
Block a user