diff --git a/packages/yew/src/html/component/children.rs b/packages/yew/src/html/component/children.rs
index c428217c116..94205309bb5 100644
--- a/packages/yew/src/html/component/children.rs
+++ b/packages/yew/src/html/component/children.rs
@@ -278,14 +278,7 @@ impl From> for Html {
impl From> for VList {
fn from(val: ChildrenRenderer) -> Self {
- if let Some(children) = val.children {
- if children.is_empty() {
- return VList::new();
- }
- VList::with_children(children, None)
- } else {
- VList::new()
- }
+ VList::from(val.children)
}
}
diff --git a/packages/yew/src/html/conversion/into_prop_value.rs b/packages/yew/src/html/conversion/into_prop_value.rs
index f7f653396be..3a75f6b42d2 100644
--- a/packages/yew/src/html/conversion/into_prop_value.rs
+++ b/packages/yew/src/html/conversion/into_prop_value.rs
@@ -170,11 +170,7 @@ impl IntoPropValue for ChildrenRenderer {
impl IntoPropValue for &ChildrenRenderer {
#[inline]
fn into_prop_value(self) -> VNode {
- if let Some(children) = self.children.clone() {
- VNode::VList(Rc::new(VList::with_children(children, None)))
- } else {
- VNode::VList(Rc::new(VList::new()))
- }
+ VNode::VList(Rc::new(VList::from(self.children.clone())))
}
}
@@ -195,18 +191,14 @@ impl IntoPropValue> for VText {
impl IntoPropValue for ChildrenRenderer {
#[inline]
fn into_prop_value(self) -> VList {
- if let Some(children) = self.children {
- VList::with_children(children, None)
- } else {
- VList::new()
- }
+ VList::from(self.children)
}
}
impl IntoPropValue for VChild {
#[inline]
fn into_prop_value(self) -> VList {
- VList::with_children(vec![self.into()], None)
+ VList::from_iter([VNode::from(self)].into_iter())
}
}
@@ -219,7 +211,7 @@ impl IntoPropValue> for AttrValue {
impl IntoPropValue for Vec {
#[inline]
fn into_prop_value(self) -> VNode {
- VNode::VList(Rc::new(VList::with_children(self, None)))
+ VNode::VList(Rc::new(VList::from_iter(self)))
}
}
diff --git a/packages/yew/src/virtual_dom/vlist.rs b/packages/yew/src/virtual_dom/vlist.rs
index 0d14a483cb2..bd366204eb4 100644
--- a/packages/yew/src/virtual_dom/vlist.rs
+++ b/packages/yew/src/virtual_dom/vlist.rs
@@ -61,6 +61,37 @@ impl DerefMut for VList {
}
}
+impl> FromIterator for VList {
+ fn from_iter>(iter: T) -> Self {
+ let children = iter.into_iter().map(|n| n.into()).collect::>();
+ if children.is_empty() {
+ VList::new()
+ } else {
+ VList {
+ children: Some(Rc::new(children)),
+ key: None,
+ fully_keyed: FullyKeyedState::KnownFullyKeyed,
+ }
+ }
+ }
+}
+
+impl From