Merge branch 'main' into fix-effect

This commit is contained in:
Evan Almloff committed 2024-03-04 15:40:37 -06:00
commit 3827378f68
49 files changed
+1100 -670

No files matched your search

+5 -9
View File
@@ -2,7 +2,9 @@
use dioxus::prelude::*;
use dioxus_core::{AttributeValue, DynamicNode, NoOpMutations, VComponent, VNode, *};
use std::{cfg, collections::HashSet, default::Default};
use std::{
cfg, collections::HashSet, default::Default, sync::atomic::AtomicUsize, sync::atomic::Ordering,
};
fn random_ns() -> Option<&'static str> {
let namespace = rand::random::<u8>() % 2;
@@ -220,20 +222,14 @@ fn create_random_dynamic_attr() -> Attribute {
)
}
static mut TEMPLATE_COUNT: usize = 0;
static TEMPLATE_COUNT: AtomicUsize = AtomicUsize::new(0);
fn create_template_location() -> &'static str {
Box::leak(
format!(
"{}{}",
concat!(file!(), ":", line!(), ":", column!(), ":"),
{
unsafe {
let old = TEMPLATE_COUNT;
TEMPLATE_COUNT += 1;
old
}
}
TEMPLATE_COUNT.fetch_add(1, Ordering::Relaxed)
)
.into_boxed_str(),
)
+82
View File
@@ -0,0 +1,82 @@
use dioxus::html::SerializedHtmlEventConverter;
use dioxus::prelude::*;
use dioxus_core::ElementId;
use std::rc::Rc;
use tracing_fluent_assertions::{AssertionRegistry, AssertionsLayer};
use tracing_subscriber::{layer::SubscriberExt, Registry};
#[test]
fn basic_tracing() {
// setup tracing
let assertion_registry = AssertionRegistry::default();
let base_subscriber = Registry::default();
// log to standard out for testing
let std_out_log = tracing_subscriber::fmt::layer().pretty();
let subscriber = base_subscriber
.with(std_out_log)
.with(AssertionsLayer::new(&assertion_registry));
tracing::subscriber::set_global_default(subscriber).unwrap();
let new_virtual_dom = assertion_registry
.build()
.with_name("VirtualDom::new")
.was_created()
.was_entered_exactly(1)
.was_closed()
.finalize();
let edited_virtual_dom = assertion_registry
.build()
.with_name("VirtualDom::rebuild")
.was_created()
.was_entered_exactly(1)
.was_closed()
.finalize();
set_event_converter(Box::new(SerializedHtmlEventConverter));
let mut dom = VirtualDom::new(app);
dom.rebuild(&mut dioxus_core::NoOpMutations);
new_virtual_dom.assert();
edited_virtual_dom.assert();
for _ in 0..3 {
dom.handle_event(
"click",
Rc::new(PlatformEventData::new(Box::<SerializedMouseData>::default())),
ElementId(2),
true,
);
dom.process_events();
_ = dom.render_immediate_to_vec();
}
}
fn app() -> Element {
let mut idx = use_signal(|| 0);
let onhover = |_| println!("go!");
rsx! {
div {
button {
onclick: move |_| {
idx += 1;
println!("Clicked");
},
"+"
}
button { onclick: move |_| idx -= 1, "-" }
ul {
{(0..idx()).map(|i| rsx! {
ChildExample { i: i, onhover: onhover }
})}
}
}
}
}
#[component]
fn ChildExample(i: i32, onhover: EventHandler<MouseEvent>) -> Element {
rsx! { li { onmouseover: move |e| onhover.call(e), "{i}" } }
}