From bea070899aab9dbc4b60fe352d72b00b15845e01 Mon Sep 17 00:00:00 2001 From: Martin Molzer Date: Sat, 5 Mar 2022 22:22:34 +0100 Subject: [PATCH] fix naming of BNode variants --- packages/yew/src/dom_bundle/bcomp.rs | 6 +- packages/yew/src/dom_bundle/blist.rs | 6 +- packages/yew/src/dom_bundle/bnode.rs | 86 ++++++++++++------------ packages/yew/src/dom_bundle/bportal.rs | 2 +- packages/yew/src/dom_bundle/bsuspense.rs | 2 +- packages/yew/src/dom_bundle/btag/mod.rs | 6 +- packages/yew/src/dom_bundle/btext.rs | 2 +- 7 files changed, 55 insertions(+), 55 deletions(-) diff --git a/packages/yew/src/dom_bundle/bcomp.rs b/packages/yew/src/dom_bundle/bcomp.rs index 51d018d402f..fe2d1ccabf0 100644 --- a/packages/yew/src/dom_bundle/bcomp.rs +++ b/packages/yew/src/dom_bundle/bcomp.rs @@ -92,7 +92,7 @@ impl Reconcilable for VComp { ) -> NodeRef { match bundle { // If the existing bundle is the same type, reuse it and update its properties - BNode::BComp(ref mut bcomp) + BNode::Comp(ref mut bcomp) if self.type_id == bcomp.type_id && self.key == bcomp.key => { self.reconcile(parent_scope, parent, next_sibling, bcomp) @@ -216,7 +216,7 @@ impl ComponentRenderState { let placeholder: Node = document().create_text_node("").into(); insert_node(&placeholder, &parent, next_sibling.get().as_ref()); node_ref.set(Some(placeholder.clone())); - BNode::BRef(placeholder) + BNode::Ref(placeholder) }; Self { root_node: placeholder, @@ -232,7 +232,7 @@ impl ComponentRenderState { use super::blist::BList; Self { - root_node: BNode::BList(BList::new()), + root_node: BNode::List(BList::new()), parent: None, next_sibling: NodeRef::default(), html_sender: Some(tx), diff --git a/packages/yew/src/dom_bundle/blist.rs b/packages/yew/src/dom_bundle/blist.rs index 6a4f0541e66..21e66fc60ec 100644 --- a/packages/yew/src/dom_bundle/blist.rs +++ b/packages/yew/src/dom_bundle/blist.rs @@ -101,11 +101,11 @@ impl BNode { /// Assert that a bundle node is a list, or convert it to a list with a single child fn make_list(&mut self) -> &mut BList { match self { - Self::BList(blist) => blist, + Self::List(blist) => blist, self_ => { - let b = std::mem::replace(self_, BNode::BList(BList::new())); + let b = std::mem::replace(self_, BNode::List(BList::new())); let self_list = match self_ { - BNode::BList(blist) => blist, + BNode::List(blist) => blist, _ => unreachable!("just been set to the variant"), }; let key = b.key().cloned(); diff --git a/packages/yew/src/dom_bundle/bnode.rs b/packages/yew/src/dom_bundle/bnode.rs index 22ed9d0b723..0e80563fd30 100644 --- a/packages/yew/src/dom_bundle/bnode.rs +++ b/packages/yew/src/dom_bundle/bnode.rs @@ -11,32 +11,32 @@ use web_sys::{Element, Node}; /// The bundle implementation to [VNode]. pub enum BNode { /// A bind between `VTag` and `Element`. - BTag(Box), + Tag(Box), /// A bind between `VText` and `TextNode`. - BText(BText), + Text(BText), /// A bind between `VComp` and `Element`. - BComp(BComp), + Comp(BComp), /// A holder for a list of other nodes. - BList(BList), + List(BList), /// A portal to another part of the document - BPortal(BPortal), + Portal(BPortal), /// A holder for any `Node` (necessary for replacing node). - BRef(Node), + Ref(Node), /// A suspendible document fragment. - BSuspense(Box), + Suspense(Box), } impl BNode { /// Get the key of the underlying node pub(super) fn key(&self) -> Option<&Key> { match self { - Self::BComp(bsusp) => bsusp.key(), - Self::BList(blist) => blist.key(), - Self::BRef(_) => None, - Self::BTag(btag) => btag.key(), - Self::BText(_) => None, - Self::BPortal(bportal) => bportal.key(), - Self::BSuspense(bsusp) => bsusp.key(), + Self::Comp(bsusp) => bsusp.key(), + Self::List(blist) => blist.key(), + Self::Ref(_) => None, + Self::Tag(btag) => btag.key(), + Self::Text(_) => None, + Self::Portal(bportal) => bportal.key(), + Self::Suspense(bsusp) => bsusp.key(), } } } @@ -45,34 +45,34 @@ impl DomBundle for BNode { /// Remove VNode from parent. fn detach(self, parent: &Element, parent_to_detach: bool) { match self { - Self::BTag(vtag) => vtag.detach(parent, parent_to_detach), - Self::BText(btext) => btext.detach(parent, parent_to_detach), - Self::BComp(bsusp) => bsusp.detach(parent, parent_to_detach), - Self::BList(blist) => blist.detach(parent, parent_to_detach), - Self::BRef(ref node) => { + Self::Tag(vtag) => vtag.detach(parent, parent_to_detach), + Self::Text(btext) => btext.detach(parent, parent_to_detach), + Self::Comp(bsusp) => bsusp.detach(parent, parent_to_detach), + Self::List(blist) => blist.detach(parent, parent_to_detach), + Self::Ref(ref node) => { // Always remove user-defined nodes to clear possible parent references of them if parent.remove_child(node).is_err() { console::warn!("Node not found to remove VRef"); } } - Self::BPortal(bportal) => bportal.detach(parent, parent_to_detach), - Self::BSuspense(bsusp) => bsusp.detach(parent, parent_to_detach), + Self::Portal(bportal) => bportal.detach(parent, parent_to_detach), + Self::Suspense(bsusp) => bsusp.detach(parent, parent_to_detach), } } fn shift(&self, next_parent: &Element, next_sibling: NodeRef) { match self { - Self::BTag(ref vtag) => vtag.shift(next_parent, next_sibling), - Self::BText(ref btext) => btext.shift(next_parent, next_sibling), - Self::BComp(ref bsusp) => bsusp.shift(next_parent, next_sibling), - Self::BList(ref vlist) => vlist.shift(next_parent, next_sibling), - Self::BRef(ref node) => { + Self::Tag(ref vtag) => vtag.shift(next_parent, next_sibling), + Self::Text(ref btext) => btext.shift(next_parent, next_sibling), + Self::Comp(ref bsusp) => bsusp.shift(next_parent, next_sibling), + Self::List(ref vlist) => vlist.shift(next_parent, next_sibling), + Self::Ref(ref node) => { next_parent .insert_before(node, next_sibling.get().as_ref()) .unwrap(); } - Self::BPortal(ref vportal) => vportal.shift(next_parent, next_sibling), - Self::BSuspense(ref vsuspense) => vsuspense.shift(next_parent, next_sibling), + Self::Portal(ref vportal) => vportal.shift(next_parent, next_sibling), + Self::Suspense(ref vsuspense) => vsuspense.shift(next_parent, next_sibling), } } } @@ -105,7 +105,7 @@ impl Reconcilable for VNode { } VNode::VRef(node) => { super::insert_node(&node, parent, next_sibling.get().as_ref()); - (NodeRef::new(node.clone()), BNode::BRef(node)) + (NodeRef::new(node.clone()), BNode::Ref(node)) } VNode::VPortal(vportal) => { let (node_ref, portal) = vportal.attach(parent_scope, parent, next_sibling); @@ -142,7 +142,7 @@ impl Reconcilable for VNode { VNode::VList(vlist) => vlist.reconcile_node(parent_scope, parent, next_sibling, bundle), VNode::VRef(node) => { let _existing = match bundle { - BNode::BRef(ref n) if &node == n => n, + BNode::Ref(ref n) if &node == n => n, _ => { return VNode::VRef(node).replace( parent_scope, @@ -167,55 +167,55 @@ impl Reconcilable for VNode { impl From for BNode { #[inline] fn from(btext: BText) -> Self { - Self::BText(btext) + Self::Text(btext) } } impl From for BNode { #[inline] fn from(blist: BList) -> Self { - Self::BList(blist) + Self::List(blist) } } impl From for BNode { #[inline] fn from(btag: BTag) -> Self { - Self::BTag(Box::new(btag)) + Self::Tag(Box::new(btag)) } } impl From for BNode { #[inline] fn from(bcomp: BComp) -> Self { - Self::BComp(bcomp) + Self::Comp(bcomp) } } impl From for BNode { #[inline] fn from(bportal: BPortal) -> Self { - Self::BPortal(bportal) + Self::Portal(bportal) } } impl From for BNode { #[inline] fn from(bsusp: BSuspense) -> Self { - Self::BSuspense(Box::new(bsusp)) + Self::Suspense(Box::new(bsusp)) } } impl fmt::Debug for BNode { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { - Self::BTag(ref vtag) => vtag.fmt(f), - Self::BText(ref btext) => btext.fmt(f), - Self::BComp(ref bsusp) => bsusp.fmt(f), - Self::BList(ref vlist) => vlist.fmt(f), - Self::BRef(ref vref) => write!(f, "VRef ( \"{}\" )", crate::utils::print_node(vref)), - Self::BPortal(ref vportal) => vportal.fmt(f), - Self::BSuspense(ref bsusp) => bsusp.fmt(f), + Self::Tag(ref vtag) => vtag.fmt(f), + Self::Text(ref btext) => btext.fmt(f), + Self::Comp(ref bsusp) => bsusp.fmt(f), + Self::List(ref vlist) => vlist.fmt(f), + Self::Ref(ref vref) => write!(f, "VRef ( \"{}\" )", crate::utils::print_node(vref)), + Self::Portal(ref vportal) => vportal.fmt(f), + Self::Suspense(ref bsusp) => bsusp.fmt(f), } } } diff --git a/packages/yew/src/dom_bundle/bportal.rs b/packages/yew/src/dom_bundle/bportal.rs index 0ddb324fdfa..a5c6d769181 100644 --- a/packages/yew/src/dom_bundle/bportal.rs +++ b/packages/yew/src/dom_bundle/bportal.rs @@ -64,7 +64,7 @@ impl Reconcilable for VPortal { bundle: &mut BNode, ) -> NodeRef { match bundle { - BNode::BPortal(portal) => self.reconcile(parent_scope, parent, next_sibling, portal), + BNode::Portal(portal) => self.reconcile(parent_scope, parent, next_sibling, portal), _ => self.replace(parent_scope, parent, next_sibling, bundle), } } diff --git a/packages/yew/src/dom_bundle/bsuspense.rs b/packages/yew/src/dom_bundle/bsuspense.rs index 4660ec95704..0781b512e7d 100644 --- a/packages/yew/src/dom_bundle/bsuspense.rs +++ b/packages/yew/src/dom_bundle/bsuspense.rs @@ -100,7 +100,7 @@ impl Reconcilable for VSuspense { ) -> NodeRef { match bundle { // We only preserve the child state if they are the same suspense. - BNode::BSuspense(m) + BNode::Suspense(m) if m.key == self.key && self.detached_parent.as_ref() == Some(&m.detached_parent) => { diff --git a/packages/yew/src/dom_bundle/btag/mod.rs b/packages/yew/src/dom_bundle/btag/mod.rs index 1153ab13a01..1d172c1f87d 100644 --- a/packages/yew/src/dom_bundle/btag/mod.rs +++ b/packages/yew/src/dom_bundle/btag/mod.rs @@ -162,7 +162,7 @@ impl Reconcilable for VTag { match bundle { // If the ancestor is a tag of the same type, don't recreate, keep the // old tag and update its attributes and children. - BNode::BTag(ex) if self.key == ex.key => { + BNode::Tag(ex) if self.key == ex.key => { if match (&self.inner, &ex.inner) { (VTagInner::Input(_), BTagInner::Input(_)) => true, (VTagInner::Textarea { .. }, BTagInner::Textarea { .. }) => true, @@ -447,7 +447,7 @@ mod tests { } fn assert_btag_ref(node: &BNode) -> &BTag { - if let BNode::BTag(vtag) = node { + if let BNode::Tag(vtag) = node { return vtag; } panic!("should be btag"); @@ -461,7 +461,7 @@ mod tests { } fn assert_btag_mut(node: &mut BNode) -> &mut BTag { - if let BNode::BTag(btag) = node { + if let BNode::Tag(btag) = node { return btag; } panic!("should be btag"); diff --git a/packages/yew/src/dom_bundle/btext.rs b/packages/yew/src/dom_bundle/btext.rs index 49cead246d5..af152955daf 100644 --- a/packages/yew/src/dom_bundle/btext.rs +++ b/packages/yew/src/dom_bundle/btext.rs @@ -59,7 +59,7 @@ impl Reconcilable for VText { bundle: &mut BNode, ) -> NodeRef { match bundle { - BNode::BText(btext) => self.reconcile(parent_scope, parent, next_sibling, btext), + BNode::Text(btext) => self.reconcile(parent_scope, parent, next_sibling, btext), _ => self.replace(parent_scope, parent, next_sibling, bundle), } }