diff --git a/crates/macro/src/html_tree/html_list.rs b/crates/macro/src/html_tree/html_list.rs
index 5da411c0333..907d9bbe5ab 100644
--- a/crates/macro/src/html_tree/html_list.rs
+++ b/crates/macro/src/html_tree/html_list.rs
@@ -53,7 +53,7 @@ impl ToTokens for HtmlList {
tokens.extend(quote! {
::yew::virtual_dom::VNode::VList(
::yew::virtual_dom::vlist::VList {
- childs: vec![#(#html_trees,)*],
+ children: vec![#(#html_trees,)*],
}
)
});
diff --git a/examples/crm/src/markdown.rs b/examples/crm/src/markdown.rs
index eff84717922..1737a7abb3b 100644
--- a/examples/crm/src/markdown.rs
+++ b/examples/crm/src/markdown.rs
@@ -36,9 +36,9 @@ where
pre.add_child(top.into());
top = pre;
} else if let Tag::Table(aligns) = tag {
- for r in top.childs.iter_mut() {
+ for r in top.children.iter_mut() {
if let &mut VNode::VTag(ref mut vtag) = r {
- for (i, c) in vtag.childs.iter_mut().enumerate() {
+ for (i, c) in vtag.children.iter_mut().enumerate() {
if let &mut VNode::VTag(ref mut vtag) = c {
match aligns[i] {
Alignment::None => {}
@@ -51,7 +51,7 @@ where
}
}
} else if let Tag::TableHead = tag {
- for c in top.childs.iter_mut() {
+ for c in top.children.iter_mut() {
if let &mut VNode::VTag(ref mut vtag) = c {
// TODO
// vtag.tag = "th".into();
diff --git a/src/html/mod.rs b/src/html/mod.rs
index 76f67b91bfa..a4ad4e24802 100644
--- a/src/html/mod.rs
+++ b/src/html/mod.rs
@@ -253,7 +253,7 @@ where
{
fn render(&self) -> Html {
VList {
- childs: self.iter().map(|c| c.into()).collect(),
+ children: self.iter().map(|c| c.into()).collect(),
}
.into()
}
diff --git a/src/virtual_dom/mod.rs b/src/virtual_dom/mod.rs
index 026eba57673..6f11ecb2da5 100644
--- a/src/virtual_dom/mod.rs
+++ b/src/virtual_dom/mod.rs
@@ -134,7 +134,7 @@ enum Reform {
/// The optional `Node` is used to insert the
/// new node in the correct slot of the parent.
///
- /// If it does not exist, a `precursor` must be
+ /// If it does not exist, a `previous_sibling` must be
/// specified (see `VDiff::apply()`).
Before(Option),
}
@@ -158,7 +158,7 @@ pub trait VDiff {
///
/// Parameters:
/// - `parent`: the parent node in the DOM.
- /// - `precursor`: the "previous node" in a list of nodes, used to efficiently
+ /// - `previous_sibling`: the "previous node" in a list of nodes, used to efficiently
/// find where to put the node.
/// - `ancestor`: the node that this node will be replacing in the DOM.
/// This method will _always_ remove the `ancestor` from the `parent`.
@@ -175,7 +175,7 @@ pub trait VDiff {
fn apply(
&mut self,
parent: &Element,
- precursor: Option<&Node>,
+ previous_sibling: Option<&Node>,
ancestor: Option>,
scope: &Scope,
) -> Option;
diff --git a/src/virtual_dom/vcomp.rs b/src/virtual_dom/vcomp.rs
index 84cb48c1813..a1c23a75365 100644
--- a/src/virtual_dom/vcomp.rs
+++ b/src/virtual_dom/vcomp.rs
@@ -264,7 +264,7 @@ where
fn apply(
&mut self,
parent: &Element,
- precursor: Option<&Node>,
+ previous_sibling: Option<&Node>,
ancestor: Option>,
env: &Scope,
) -> Option {
@@ -308,11 +308,12 @@ where
.insert_before(&element, &sibling)
.expect("can't insert dummy element for a component");
} else {
- let precursor = precursor.and_then(|before| before.next_sibling());
- if let Some(precursor) = precursor {
+ let previous_sibling =
+ previous_sibling.and_then(|before| before.next_sibling());
+ if let Some(previous_sibling) = previous_sibling {
parent
- .insert_before(&element, &precursor)
- .expect("can't insert dummy element before precursor");
+ .insert_before(&element, &previous_sibling)
+ .expect("can't insert dummy element before previous_sibling");
} else {
parent.append_child(&element);
}
diff --git a/src/virtual_dom/vlist.rs b/src/virtual_dom/vlist.rs
index 020ca21a7b0..6be18cd3569 100644
--- a/src/virtual_dom/vlist.rs
+++ b/src/virtual_dom/vlist.rs
@@ -6,7 +6,7 @@ use stdweb::web::{Element, Node};
/// This struct represents a fragment of the Virtual DOM tree.
pub struct VList {
/// The list of children nodes. Which also could have their own children.
- pub childs: Vec>,
+ pub children: Vec>,
}
impl Default for VList {
@@ -18,12 +18,14 @@ impl Default for VList {
impl VList {
/// Creates a new empty `VList` instance.
pub fn new() -> Self {
- VList { childs: Vec::new() }
+ VList {
+ children: Vec::new(),
+ }
}
/// Add `VNode` child.
pub fn add_child(&mut self, child: VNode) {
- self.childs.push(child);
+ self.children.push(child);
}
}
@@ -32,7 +34,7 @@ impl VDiff for VList {
fn detach(&mut self, parent: &Element) -> Option {
let mut last_sibling = None;
- for mut child in self.childs.drain(..) {
+ for mut child in self.children.drain(..) {
last_sibling = child.detach(parent);
}
last_sibling
@@ -41,18 +43,18 @@ impl VDiff for VList {
fn apply(
&mut self,
parent: &Element,
- precursor: Option<&Node>,
+ previous_sibling: Option<&Node>,
ancestor: Option>,
env: &Scope,
) -> Option {
- // Reuse precursor, because fragment reuse parent
- let mut precursor = precursor.map(|node| node.to_owned());
+ // Reuse previous_sibling, because fragment reuse parent
+ let mut previous_sibling = previous_sibling.cloned();
let mut rights = {
match ancestor {
// If element matched this type
Some(VNode::VList(vlist)) => {
// Previously rendered items
- vlist.childs
+ vlist.children
}
Some(vnode) => {
// Use the current node as a single fragment list
@@ -63,25 +65,26 @@ impl VDiff for VList {
}
};
- if self.childs.is_empty() {
+ if self.children.is_empty() {
// Fixes: https://github.com/yewstack/yew/issues/294
// Without a placeholder the next element becomes first
// and corrupts the order of rendering
// We use empty text element to stake out a place
let placeholder = VText::new("".into());
- self.childs.push(placeholder.into());
+ self.children.push(placeholder.into());
}
// Process children
- let mut lefts = self.childs.iter_mut();
+ let mut lefts = self.children.iter_mut();
let mut rights = rights.drain(..);
loop {
match (lefts.next(), rights.next()) {
(Some(left), Some(right)) => {
- precursor = left.apply(parent, precursor.as_ref(), Some(right), &env);
+ previous_sibling =
+ left.apply(parent, previous_sibling.as_ref(), Some(right), &env);
}
(Some(left), None) => {
- precursor = left.apply(parent, precursor.as_ref(), None, &env);
+ previous_sibling = left.apply(parent, previous_sibling.as_ref(), None, &env);
}
(None, Some(ref mut right)) => {
right.detach(parent);
@@ -89,6 +92,6 @@ impl VDiff for VList {
(None, None) => break,
}
}
- precursor
+ previous_sibling
}
}
diff --git a/src/virtual_dom/vnode.rs b/src/virtual_dom/vnode.rs
index 2f789df1233..49ee7b33df8 100644
--- a/src/virtual_dom/vnode.rs
+++ b/src/virtual_dom/vnode.rs
@@ -44,15 +44,15 @@ impl VDiff for VNode {
fn apply(
&mut self,
parent: &Element,
- precursor: Option<&Node>,
+ previous_sibling: Option<&Node>,
ancestor: Option>,
env: &Scope,
) -> Option {
match *self {
- VNode::VTag(ref mut vtag) => vtag.apply(parent, precursor, ancestor, env),
- VNode::VText(ref mut vtext) => vtext.apply(parent, precursor, ancestor, env),
- VNode::VComp(ref mut vcomp) => vcomp.apply(parent, precursor, ancestor, env),
- VNode::VList(ref mut vlist) => vlist.apply(parent, precursor, ancestor, env),
+ VNode::VTag(ref mut vtag) => vtag.apply(parent, previous_sibling, ancestor, env),
+ VNode::VText(ref mut vtext) => vtext.apply(parent, previous_sibling, ancestor, env),
+ VNode::VComp(ref mut vcomp) => vcomp.apply(parent, previous_sibling, ancestor, env),
+ VNode::VList(ref mut vlist) => vlist.apply(parent, previous_sibling, ancestor, env),
VNode::VRef(ref mut node) => {
let sibling = match ancestor {
Some(mut n) => n.detach(parent),
diff --git a/src/virtual_dom/vtag.rs b/src/virtual_dom/vtag.rs
index 263f3b15ff0..a25f4262893 100644
--- a/src/virtual_dom/vtag.rs
+++ b/src/virtual_dom/vtag.rs
@@ -32,7 +32,7 @@ pub struct VTag {
/// List of attributes.
pub attributes: Attributes,
/// The list of children nodes. Which also could have own children.
- pub childs: Vec>,
+ pub children: Vec>,
/// List of attached classes.
pub classes: Classes,
/// Contains a value of an
@@ -63,7 +63,7 @@ impl VTag {
attributes: Attributes::new(),
listeners: Vec::new(),
captured: Vec::new(),
- childs: Vec::new(),
+ children: Vec::new(),
value: None,
kind: None,
// In HTML node `checked` attribute sets `defaultChecked` parameter,
@@ -79,13 +79,13 @@ impl VTag {
/// Add `VNode` child.
pub fn add_child(&mut self, child: VNode) {
- self.childs.push(child);
+ self.children.push(child);
}
/// Add multiple `VNode` children.
pub fn add_children(&mut self, children: Vec>) {
for child in children {
- self.childs.push(child);
+ self.children.push(child);
}
}
@@ -352,7 +352,7 @@ impl VDiff for VTag {
.expect("tried to remove not rendered VTag from DOM");
// recursively remove its children
- self.childs.drain(..).for_each(|mut child| {
+ self.children.drain(..).for_each(|mut child| {
child.detach(&node);
});
@@ -368,7 +368,7 @@ impl VDiff for VTag {
fn apply(
&mut self,
parent: &Element,
- precursor: Option<&Node>,
+ previous_sibling: Option<&Node>,
ancestor: Option>,
env: &Scope,
) -> Option {
@@ -425,11 +425,12 @@ impl VDiff for VTag {
.insert_before(&element, &sibling)
.expect("can't insert tag before sibling");
} else {
- let precursor = precursor.and_then(|before| before.next_sibling());
- if let Some(precursor) = precursor {
+ let previous_sibling =
+ previous_sibling.and_then(|before| before.next_sibling());
+ if let Some(previous_sibling) = previous_sibling {
parent
- .insert_before(&element, &precursor)
- .expect("can't insert tag before precursor");
+ .insert_before(&element, &previous_sibling)
+ .expect("can't insert tag before previous_sibling");
} else {
parent.append_child(&element);
}
@@ -457,14 +458,15 @@ impl VDiff for VTag {
}
// Process children
- // Start with an empty precursor, because it put childs to itself
- let mut precursor = None;
- let mut self_childs = self.childs.iter_mut();
- let mut ancestor_childs = ancestor.into_iter().flat_map(|a| a.childs);
+ // Start with an empty previous_sibling, because it put children to itself
+ let mut previous_sibling = None;
+ let mut self_children = self.children.iter_mut();
+ let mut ancestor_children = ancestor.into_iter().flat_map(|a| a.children);
loop {
- match (self_childs.next(), ancestor_childs.next()) {
+ match (self_children.next(), ancestor_children.next()) {
(Some(left), right) => {
- precursor = left.apply(&element, precursor.as_ref(), right, &env);
+ previous_sibling =
+ left.apply(&element, previous_sibling.as_ref(), right, &env);
}
(None, Some(ref mut right)) => {
right.detach(&element);
@@ -514,7 +516,7 @@ impl PartialEq for VTag {
&& self.attributes == other.attributes
&& self.classes.set.len() == other.classes.set.len()
&& self.classes.set.iter().eq(other.classes.set.iter())
- && &self.childs == &other.childs
+ && &self.children == &other.children
}
}
diff --git a/src/virtual_dom/vtext.rs b/src/virtual_dom/vtext.rs
index 2b88b485fe4..c566f7698f2 100644
--- a/src/virtual_dom/vtext.rs
+++ b/src/virtual_dom/vtext.rs
@@ -48,13 +48,13 @@ impl VDiff for VText {
/// Renders virtual node over existent `TextNode`, but
/// only if value of text had changed.
- /// Parameter `precursor` is necessary for `VTag` and `VList` which
+ /// Parameter `previous_sibling` is necessary for `VTag` and `VList` which
/// has children and renders them.
fn apply(
&mut self,
parent: &Element,
_: Option<&Node>,
- opposite: Option>,
+ ancestor: Option>,
_: &Scope,
) -> Option {
assert!(
@@ -62,7 +62,7 @@ impl VDiff for VText {
"reference is ignored so must not be set"
);
let reform = {
- match opposite {
+ match ancestor {
// If element matched this type
Some(VNode::VText(mut vtext)) => {
self.reference = vtext.reference.take();
@@ -82,12 +82,12 @@ impl VDiff for VText {
};
match reform {
Reform::Keep => {}
- Reform::Before(node) => {
+ Reform::Before(ancestor) => {
let element = document().create_text_node(&self.text);
- if let Some(sibling) = node {
+ if let Some(ancestor) = ancestor {
parent
- .insert_before(&element, &sibling)
- .expect("can't insert text before sibling");
+ .insert_before(&element, &ancestor)
+ .expect("can't insert text before ancestor");
} else {
parent.append_child(&element);
}
diff --git a/tests/vtag_test.rs b/tests/vtag_test.rs
index bccfd25337b..9135ee27aae 100644
--- a/tests/vtag_test.rs
+++ b/tests/vtag_test.rs
@@ -255,7 +255,7 @@ fn supports_svg() {
let svg_tag = assert_vtag(&mut svg_node);
svg_tag.apply(&div_el, None, None, &scope);
assert_namespace(svg_tag, SVG_NAMESPACE);
- let path_tag = assert_vtag(svg_tag.childs.get_mut(0).unwrap());
+ let path_tag = assert_vtag(svg_tag.children.get_mut(0).unwrap());
assert_namespace(path_tag, SVG_NAMESPACE);
let g_tag = assert_vtag(&mut g_node);