diff --git a/crates/concoct/Cargo.toml b/crates/concoct/Cargo.toml index 909817d1..04f06ed9 100644 --- a/crates/concoct/Cargo.toml +++ b/crates/concoct/Cargo.toml @@ -7,13 +7,13 @@ description = "Cross-platform UI framework" repository = "https://github.com/concoct-rs/concoct" [features] -full = [] +full = ["tracing"] [dependencies] futures = "0.3.30" rustc-hash = "1.1.0" slotmap = "1.0.7" -tracing = "0.1.40" +tracing = { version ="0.1.40", optional = true } [package.metadata.docs.rs] features = ["full"] diff --git a/crates/concoct/src/lib.rs b/crates/concoct/src/lib.rs index 3f8fa5d9..234c6b8e 100644 --- a/crates/concoct/src/lib.rs +++ b/crates/concoct/src/lib.rs @@ -31,6 +31,9 @@ use std::cell::RefCell; pub mod hook; +#[macro_use] +pub(crate) mod macros; + mod rt; pub(crate) use self::rt::{Runtime, Scope}; diff --git a/crates/concoct/src/macros.rs b/crates/concoct/src/macros.rs new file mode 100644 index 00000000..612e081e --- /dev/null +++ b/crates/concoct/src/macros.rs @@ -0,0 +1,8 @@ +//! Internal macros + +macro_rules! trace { + ($($tt:tt)*) => { + #[cfg(feature = "tracing")] + tracing::trace!($($tt)*) + } +} diff --git a/crates/concoct/src/tree/node.rs b/crates/concoct/src/tree/node.rs index cb1b5914..032e18c3 100644 --- a/crates/concoct/src/tree/node.rs +++ b/crates/concoct/src/tree/node.rs @@ -1,6 +1,9 @@ use crate::{Runtime, Scope, Tree, ViewBuilder}; use slotmap::DefaultKey; -use std::{any::Any, mem}; +use std::{ + any::{self, Any}, + mem, +}; pub struct Node { pub(crate) view: V, @@ -33,6 +36,8 @@ where cx_ref.scope = Some(self.scope.clone().unwrap()); drop(cx_ref); + trace!("rebuilding from {}", any::type_name::()); + let view = unsafe { mem::transmute(&self.view) }; let body = (self.builder)(view); @@ -60,6 +65,8 @@ where cx_ref.scope = Some(self.scope.clone().unwrap()); drop(cx_ref); + trace!("building {}", any::type_name::()); + let view = unsafe { mem::transmute(&self.view) }; let body = (self.builder)(view); @@ -100,6 +107,8 @@ where cx_ref.scope = Some(self.scope.clone().unwrap()); drop(cx_ref); + trace!("rebuilding {}", any::type_name::()); + let view = unsafe { mem::transmute(&self.view) }; let body = (self.builder)(view); @@ -120,11 +129,15 @@ where let mut cx_ref = cx.inner.borrow_mut(); cx_ref.contexts = parent_contexts; } else { + trace!("skipping {}", any::type_name::()); + self.body = last.body.take(); } } unsafe fn remove(&mut self) { + trace!("removing {}", any::type_name::()); + let cx = Runtime::current(); let mut cx_ref = cx.inner.borrow_mut(); let key = self.key.unwrap();