Skip to content

Commit

Permalink
Add VTag::into_children (yewstack#2638)
Browse files Browse the repository at this point in the history
* Add `VTag::into_children`

Currently, VTag supports `children` and `children_mut`, but not `into_children` to complete the pattern. This is useful if someone wishes to destructively acquire the children of a VTag to reparent them to a different VTag.

* Repair broken doc comment on `VTag::children_mut`

* Remove spaces between functions
  • Loading branch information
LLBlumire authored Apr 23, 2022
1 parent 1794dd0 commit 2db4c81
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/yew/src/virtual_dom/vtag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,14 +297,22 @@ impl VTag {
}

/// Returns a mutable reference to the children of this [VTag], if the node can have
// children
/// children
pub fn children_mut(&mut self) -> Option<&mut VList> {
match &mut self.inner {
VTagInner::Other { children, .. } => Some(children),
_ => None,
}
}

/// Returns the children of this [VTag]
pub fn into_children(self) -> VList {
match self.inner {
VTagInner::Other { children, .. } => children,
_ => VList::new(),
}
}

/// Returns the `value` of an
/// [InputElement](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input) or
/// [TextArea](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/textarea)
Expand Down

0 comments on commit 2db4c81

Please sign in to comment.