wip: remove portals completely

This commit is contained in:
Jonathan Kelley committed 2021-12-14 21:46:19 -05:00
1 parent 8daf7a6ed8
commit 2fd56e7619
17 files changed
+259 -404

No files matched your search

-96
View File
@@ -114,22 +114,6 @@ pub enum VNode<'src> {
/// }
/// ```
Placeholder(&'src VPlaceholder),
/// A VNode that is actually a pointer to some nodes rather than the nodes directly. Useful when rendering portals
/// or eliding lifetimes on VNodes through runtime checks.
///
/// Linked VNodes can only be made through the [`Context::render`] method
///
/// Typically, linked nodes are found *not* in a VNode. When NodeLinks are in a VNode, the NodeLink was passed into
/// an `rsx!` call.
///
/// # Example
/// ```rust, ignore
/// let mut vdom = VirtualDom::new();
///
/// let node: NodeLink = vdom.render_vnode(rsx!( "hello" ));
/// ```
Portal(VPortal),
}
impl<'src> VNode<'src> {
@@ -141,7 +125,6 @@ impl<'src> VNode<'src> {
VNode::Fragment(f) => f.key,
VNode::Text(_t) => None,
VNode::Placeholder(_f) => None,
VNode::Portal(_c) => None,
}
}
@@ -160,7 +143,6 @@ impl<'src> VNode<'src> {
VNode::Text(el) => el.dom_id.get(),
VNode::Element(el) => el.dom_id.get(),
VNode::Placeholder(el) => el.dom_id.get(),
VNode::Portal(_) => None,
VNode::Fragment(_) => None,
VNode::Component(_) => None,
}
@@ -184,11 +166,6 @@ impl<'src> VNode<'src> {
children: f.children,
key: f.key,
}),
VNode::Portal(c) => VNode::Portal(VPortal {
scope_id: c.scope_id.clone(),
link_idx: c.link_idx.clone(),
node: c.node,
}),
}
}
}
@@ -207,7 +184,6 @@ impl Debug for VNode<'_> {
write!(s, "VNode::VFragment {{ children: {:?} }}", frag.children)
}
VNode::Component(comp) => write!(s, "VNode::VComponent {{ fc: {:?}}}", comp.user_fc),
VNode::Portal(c) => write!(s, "VNode::VCached {{ scope_id: {:?} }}", c.scope_id.get()),
}
}
}
@@ -368,32 +344,6 @@ impl Clone for EventHandler<'_> {
}
}
/// A cached node is a "pointer" to a "rendered" node in a particular scope
///
/// It does not provide direct access to the node, so it doesn't carry any lifetime information with it
///
/// It is used during the diffing/rendering process as a runtime key into an existing set of nodes. The "render" key
/// is essentially a unique key to guarantee safe usage of the Node.
///
/// Linked VNodes can only be made through the [`Context::render`] method
///
/// Typically, NodeLinks are found *not* in a VNode. When NodeLinks are in a VNode, the NodeLink was passed into
/// an `rsx!` call.
///
/// todo: remove the raw pointer and use runtime checks instead
#[derive(Debug)]
pub struct VPortal {
pub(crate) link_idx: Cell<usize>,
pub(crate) scope_id: Cell<Option<ScopeId>>,
pub(crate) node: *const VNode<'static>,
}
impl PartialEq for VPortal {
fn eq(&self, other: &Self) -> bool {
self.node == other.node
}
}
/// Virtual Components for custom user-defined components
/// Only supports the functional syntax
pub struct VComponent<'src> {
@@ -824,49 +774,3 @@ impl IntoVNode<'_> for Arguments<'_> {
cx.text(self)
}
}
// called cx.render from a helper function
impl IntoVNode<'_> for Option<VPortal> {
fn into_vnode(self, _cx: NodeFactory) -> VNode {
match self {
Some(node) => VNode::Portal(node),
None => {
todo!()
}
}
}
}
// essentially passing elements through props
// just build a new element in place
impl IntoVNode<'_> for &Option<VPortal> {
fn into_vnode(self, _cx: NodeFactory) -> VNode {
match self {
Some(node) => VNode::Portal(VPortal {
link_idx: node.link_idx.clone(),
scope_id: node.scope_id.clone(),
node: node.node,
}),
None => {
//
todo!()
}
}
}
}
impl IntoVNode<'_> for VPortal {
fn into_vnode(self, _cx: NodeFactory) -> VNode {
VNode::Portal(self)
}
}
impl IntoVNode<'_> for &VPortal {
fn into_vnode(self, _cx: NodeFactory) -> VNode {
VNode::Portal(VPortal {
link_idx: self.link_idx.clone(),
scope_id: self.scope_id.clone(),
node: self.node,
})
}
}