wip: memoize dom in the prescence of identical components
This commit is contained in:
1 parent
7cf15ee4e8
commit
cb2782b4bb
27 files changed
+474
-219
No files matched your search
@@ -395,12 +395,16 @@ impl<P> AnyProps for VComponentProps<P> {
|
||||
/// This struct adds metadata to the final VNode about listeners, attributes, and children
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct NodeFactory<'a> {
|
||||
pub(crate) scope: &'a ScopeState,
|
||||
pub(crate) bump: &'a Bump,
|
||||
}
|
||||
|
||||
impl<'a> NodeFactory<'a> {
|
||||
pub fn new(bump: &'a Bump) -> NodeFactory<'a> {
|
||||
NodeFactory { bump }
|
||||
pub fn new(scope: &'a ScopeState) -> NodeFactory<'a> {
|
||||
NodeFactory {
|
||||
scope,
|
||||
bump: &scope.wip_frame().bump,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@@ -473,6 +477,12 @@ impl<'a> NodeFactory<'a> {
|
||||
) -> VNode<'a> {
|
||||
let key = key.map(|f| self.raw_text(f).0);
|
||||
|
||||
let mut items = self.scope.items.borrow_mut();
|
||||
for listener in listeners {
|
||||
let long_listener = unsafe { std::mem::transmute(listener) };
|
||||
items.listeners.push(long_listener);
|
||||
}
|
||||
|
||||
VNode::Element(self.bump.alloc(VElement {
|
||||
tag: tag_name,
|
||||
key,
|
||||
@@ -511,7 +521,7 @@ impl<'a> NodeFactory<'a> {
|
||||
where
|
||||
P: Properties + 'a,
|
||||
{
|
||||
VNode::Component(self.bump.alloc(VComponent {
|
||||
let vcomp = self.bump.alloc(VComponent {
|
||||
key: key.map(|f| self.raw_text(f).0),
|
||||
scope: Default::default(),
|
||||
can_memoize: P::IS_STATIC,
|
||||
@@ -528,7 +538,15 @@ impl<'a> NodeFactory<'a> {
|
||||
// the transformation from this specific lifetime to the for<'a> lifetime
|
||||
render_fn: unsafe { std::mem::transmute(component) },
|
||||
}))),
|
||||
}))
|
||||
});
|
||||
|
||||
if !P::IS_STATIC {
|
||||
let vcomp = &*vcomp;
|
||||
let vcomp = unsafe { std::mem::transmute(vcomp) };
|
||||
self.scope.items.borrow_mut().borrowed_props.push(vcomp);
|
||||
}
|
||||
|
||||
VNode::Component(vcomp)
|
||||
}
|
||||
|
||||
pub fn listener(self, event: &'static str, callback: EventHandler<'a>) -> Listener<'a> {
|
||||
@@ -730,8 +748,11 @@ impl IntoVNode<'_> for Arguments<'_> {
|
||||
|
||||
impl<'a> IntoVNode<'a> for &Option<VNode<'a>> {
|
||||
fn into_vnode(self, cx: NodeFactory<'a>) -> VNode<'a> {
|
||||
let r = self.as_ref().map(|f| f.decouple());
|
||||
cx.fragment_from_iter(r)
|
||||
self.as_ref()
|
||||
.map(|f| f.decouple())
|
||||
.unwrap_or(VNode::Placeholder(
|
||||
cx.bump.alloc(VPlaceholder { id: empty_cell() }),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user