|
@@ -187,11 +187,7 @@ impl Debug for VNode<'_> {
|
|
|
|
|
|
VNode::Fragment(frag) => write!(s, "VFragment {{ children: {:?} }}", frag.children),
|
|
VNode::Fragment(frag) => write!(s, "VFragment {{ children: {:?} }}", frag.children),
|
|
VNode::Suspended { .. } => write!(s, "VSuspended"),
|
|
VNode::Suspended { .. } => write!(s, "VSuspended"),
|
|
- VNode::Component(comp) => write!(
|
|
|
|
- s,
|
|
|
|
- "VComponent {{ fc: {:?}, children: {:?} }}",
|
|
|
|
- comp.user_fc, comp.children
|
|
|
|
- ),
|
|
|
|
|
|
+ VNode::Component(comp) => write!(s, "VComponent {{ fc: {:?}}}", comp.user_fc),
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -331,8 +327,6 @@ pub struct VComponent<'src> {
|
|
|
|
|
|
pub(crate) caller: &'src dyn for<'b> Fn(&'b ScopeInner) -> Element<'b>,
|
|
pub(crate) caller: &'src dyn for<'b> Fn(&'b ScopeInner) -> Element<'b>,
|
|
|
|
|
|
- pub(crate) children: &'src [VNode<'src>],
|
|
|
|
-
|
|
|
|
pub(crate) comparator: Option<&'src dyn Fn(&VComponent) -> bool>,
|
|
pub(crate) comparator: Option<&'src dyn Fn(&VComponent) -> bool>,
|
|
|
|
|
|
pub(crate) drop_props: RefCell<Option<BumpBox<'src, dyn FnMut()>>>,
|
|
pub(crate) drop_props: RefCell<Option<BumpBox<'src, dyn FnMut()>>>,
|
|
@@ -483,20 +477,16 @@ impl<'a> NodeFactory<'a> {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- pub fn component<P, V>(
|
|
|
|
|
|
+ pub fn component<P>(
|
|
&self,
|
|
&self,
|
|
component: fn(Scope<'a, P>) -> Element<'a>,
|
|
component: fn(Scope<'a, P>) -> Element<'a>,
|
|
props: P,
|
|
props: P,
|
|
key: Option<Arguments>,
|
|
key: Option<Arguments>,
|
|
- children: V,
|
|
|
|
) -> VNode<'a>
|
|
) -> VNode<'a>
|
|
where
|
|
where
|
|
P: Properties + 'a,
|
|
P: Properties + 'a,
|
|
- V: AsRef<[VNode<'a>]> + 'a,
|
|
|
|
{
|
|
{
|
|
let bump = self.bump();
|
|
let bump = self.bump();
|
|
- let children: &'a V = bump.alloc(children);
|
|
|
|
- let children = children.as_ref();
|
|
|
|
let props = bump.alloc(props);
|
|
let props = bump.alloc(props);
|
|
let raw_props = props as *mut P as *mut ();
|
|
let raw_props = props as *mut P as *mut ();
|
|
let user_fc = component as *const ();
|
|
let user_fc = component as *const ();
|
|
@@ -518,7 +508,7 @@ impl<'a> NodeFactory<'a> {
|
|
|
|
|
|
// It's only okay to memoize if there are no children and the props can be memoized
|
|
// It's only okay to memoize if there are no children and the props can be memoized
|
|
// Implementing memoize is unsafe and done automatically with the props trait
|
|
// Implementing memoize is unsafe and done automatically with the props trait
|
|
- matches!((props_memoized, children.is_empty()), (true, true))
|
|
|
|
|
|
+ props_memoized
|
|
} else {
|
|
} else {
|
|
false
|
|
false
|
|
}
|
|
}
|
|
@@ -549,8 +539,6 @@ impl<'a> NodeFactory<'a> {
|
|
RefCell::new(Some(drop_props))
|
|
RefCell::new(Some(drop_props))
|
|
};
|
|
};
|
|
|
|
|
|
- let is_static = children.is_empty() && P::IS_STATIC && key.is_none();
|
|
|
|
-
|
|
|
|
let key = key.map(|f| self.raw_text(f).0);
|
|
let key = key.map(|f| self.raw_text(f).0);
|
|
|
|
|
|
let caller: &'a mut dyn for<'b> Fn(&'b ScopeInner) -> Element<'b> =
|
|
let caller: &'a mut dyn for<'b> Fn(&'b ScopeInner) -> Element<'b> =
|
|
@@ -565,17 +553,14 @@ impl<'a> NodeFactory<'a> {
|
|
unsafe { std::mem::transmute(res) }
|
|
unsafe { std::mem::transmute(res) }
|
|
});
|
|
});
|
|
|
|
|
|
- let can_memoize = children.is_empty() && P::IS_STATIC;
|
|
|
|
-
|
|
|
|
VNode::Component(bump.alloc(VComponent {
|
|
VNode::Component(bump.alloc(VComponent {
|
|
user_fc,
|
|
user_fc,
|
|
comparator,
|
|
comparator,
|
|
raw_props,
|
|
raw_props,
|
|
- children,
|
|
|
|
caller,
|
|
caller,
|
|
- is_static,
|
|
|
|
|
|
+ is_static: P::IS_STATIC,
|
|
key,
|
|
key,
|
|
- can_memoize,
|
|
|
|
|
|
+ can_memoize: P::IS_STATIC,
|
|
drop_props,
|
|
drop_props,
|
|
associated_scope: Cell::new(None),
|
|
associated_scope: Cell::new(None),
|
|
}))
|
|
}))
|
|
@@ -770,6 +755,18 @@ pub struct ScopeChildren<'a> {
|
|
root: Option<VNode<'a>>,
|
|
root: Option<VNode<'a>>,
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+impl Default for ScopeChildren<'_> {
|
|
|
|
+ fn default() -> Self {
|
|
|
|
+ Self { root: None }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+impl<'a> ScopeChildren<'a> {
|
|
|
|
+ pub fn new(root: VNode<'a>) -> Self {
|
|
|
|
+ Self { root: Some(root) }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
impl IntoIterator for &ScopeChildren<'_> {
|
|
impl IntoIterator for &ScopeChildren<'_> {
|
|
type Item = Self;
|
|
type Item = Self;
|
|
|
|
|