mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-23 12:43:08 +00:00
chore: improve debugability of fcptrs and vcomponents
this commit changes the fc slot type from a thin pointer to a c pointer. this lets us provide frame inspection of components using backtrace.
This commit is contained in:
parent
0820e18d3d
commit
120ee18368
3 changed files with 16 additions and 9 deletions
|
@ -4,7 +4,7 @@
|
|||
//! cheap and *very* fast to construct - building a full tree should be quick.
|
||||
|
||||
use crate::{
|
||||
innerlude::{Element, Properties, Scope, ScopeId, ScopeState},
|
||||
innerlude::{ComponentPtr, Element, Properties, Scope, ScopeId, ScopeState},
|
||||
lazynodes::LazyNodes,
|
||||
AnyEvent, Component,
|
||||
};
|
||||
|
@ -177,11 +177,18 @@ impl Debug for VNode<'_> {
|
|||
.field("children", &el.children)
|
||||
.finish(),
|
||||
VNode::Text(t) => write!(s, "VNode::VText {{ text: {} }}", t.text),
|
||||
VNode::Placeholder(_) => write!(s, "VNode::VPlaceholder"),
|
||||
VNode::Placeholder(t) => write!(s, "VNode::VPlaceholder {{ id: {:?} }}", t.id),
|
||||
VNode::Fragment(frag) => {
|
||||
write!(s, "VNode::VFragment {{ children: {:?} }}", frag.children)
|
||||
}
|
||||
VNode::Component(comp) => write!(s, "VNode::VComponent {{ fc: {:?}}}", comp.user_fc),
|
||||
VNode::Component(comp) => s
|
||||
.debug_struct("VNode::VComponent")
|
||||
.field("name", &comp.fn_name)
|
||||
.field("fnptr", &comp.user_fc)
|
||||
.field("key", &comp.key)
|
||||
.field("scope", &comp.scope)
|
||||
.field("originator", &comp.originator)
|
||||
.finish(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -384,7 +391,7 @@ pub struct VComponent<'src> {
|
|||
pub originator: ScopeId,
|
||||
pub scope: Cell<Option<ScopeId>>,
|
||||
pub can_memoize: bool,
|
||||
pub user_fc: *const (),
|
||||
pub user_fc: ComponentPtr,
|
||||
pub fn_name: &'static str,
|
||||
pub props: RefCell<Option<Box<dyn AnyProps + 'src>>>,
|
||||
}
|
||||
|
@ -559,7 +566,7 @@ impl<'a> NodeFactory<'a> {
|
|||
key: key.map(|f| self.raw_text(f).0),
|
||||
scope: Default::default(),
|
||||
can_memoize: P::IS_STATIC,
|
||||
user_fc: component as *const (),
|
||||
user_fc: component as ComponentPtr,
|
||||
originator: self.scope.scope_id(),
|
||||
fn_name,
|
||||
props: RefCell::new(Some(Box::new(VComponentProps {
|
||||
|
|
|
@ -13,7 +13,7 @@ use std::{
|
|||
rc::Rc,
|
||||
};
|
||||
|
||||
pub(crate) type FcSlot = *const ();
|
||||
pub(crate) type ComponentPtr = *mut std::os::raw::c_void;
|
||||
|
||||
pub(crate) struct Heuristic {
|
||||
hook_arena_size: usize,
|
||||
|
@ -28,7 +28,7 @@ pub(crate) struct ScopeArena {
|
|||
pub scope_gen: Cell<usize>,
|
||||
pub bump: Bump,
|
||||
pub scopes: RefCell<FxHashMap<ScopeId, *mut ScopeState>>,
|
||||
pub heuristics: RefCell<FxHashMap<FcSlot, Heuristic>>,
|
||||
pub heuristics: RefCell<FxHashMap<ComponentPtr, Heuristic>>,
|
||||
pub free_scopes: RefCell<Vec<*mut ScopeState>>,
|
||||
pub nodes: RefCell<Slab<*const VNode<'static>>>,
|
||||
pub tasks: Rc<TaskQueue>,
|
||||
|
@ -82,7 +82,7 @@ impl ScopeArena {
|
|||
|
||||
pub(crate) fn new_with_key(
|
||||
&self,
|
||||
fc_ptr: *const (),
|
||||
fc_ptr: ComponentPtr,
|
||||
vcomp: Box<dyn AnyProps>,
|
||||
parent_scope: Option<ScopeId>,
|
||||
container: ElementId,
|
||||
|
|
|
@ -212,7 +212,7 @@ impl VirtualDom {
|
|||
let scopes = ScopeArena::new(channel.0.clone());
|
||||
|
||||
scopes.new_with_key(
|
||||
root as *const _,
|
||||
root as ComponentPtr,
|
||||
Box::new(VComponentProps {
|
||||
props: root_props,
|
||||
memo: |_a, _b| unreachable!("memo on root will neve be run"),
|
||||
|
|
Loading…
Reference in a new issue