Skip to content

Commit

Permalink
Ran cargo fmt.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrh0057 committed Apr 4, 2020
1 parent 66be935 commit b9bd4af
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 39 deletions.
15 changes: 9 additions & 6 deletions crates/macro/src/html_tree/html_component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ impl ToTokens for HtmlComponent {
quote! { ::yew::html::NodeRef::default() }
};

let key = if let Some(key) = props.key(){
let key = if let Some(key) = props.key() {
quote_spanned! { key.span() => #key }
} else {
quote! { String::default() }
Expand Down Expand Up @@ -349,13 +349,13 @@ enum Props {
struct ListProps {
props: Vec<HtmlProp>,
node_ref: Option<Expr>,
key: Option<Expr>
key: Option<Expr>,
}

struct WithProps {
props: Ident,
node_ref: Option<Expr>,
key: Option<Expr>
key: Option<Expr>,
}

impl Props {
Expand Down Expand Up @@ -400,7 +400,7 @@ impl Parse for Props {
props = Props::With(Box::new(WithProps {
props: input.parse::<Ident>()?,
node_ref: None,
key:None
key: None,
}));

// Handle optional comma
Expand Down Expand Up @@ -445,7 +445,7 @@ impl Parse for Props {
*props = Props::List(Box::new(ListProps {
props: vec![prop],
node_ref: None,
key: None
key: None,
}));
}
Props::With(_) => {
Expand All @@ -459,7 +459,10 @@ impl Parse for Props {

match props {
Props::None => {}
Props::With(ref mut p) =>{ p.node_ref = node_ref; p.key=key},
Props::With(ref mut p) => {
p.node_ref = node_ref;
p.key = key
}
Props::List(ref mut p) => {
p.node_ref = node_ref;
p.key = key;
Expand Down
2 changes: 1 addition & 1 deletion crates/macro/src/html_tree/html_tag/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl ToTokens for HtmlTag {
node_ref,
key,
href,
listeners
listeners,
} = &attributes;

let vtag = Ident::new("__yew_vtag", tag_name.span());
Expand Down
2 changes: 1 addition & 1 deletion crates/macro/src/html_tree/html_tag/tag_attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ impl Parse for TagAttributes {
kind,
node_ref,
href,
key
key,
})
}
}
18 changes: 11 additions & 7 deletions src/virtual_dom/vcomp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub struct VComp {
type_id: TypeId,
state: MountState,
pub(crate) node_ref: NodeRef,
pub(crate) key: String
pub(crate) key: String,
}

/// A virtual child component.
Expand All @@ -40,15 +40,15 @@ pub struct VChild<COMP: Component> {
pub props: COMP::Properties,
/// Reference to the mounted node
node_ref: NodeRef,
key: String
key: String,
}

impl<COMP: Component> Clone for VChild<COMP> {
fn clone(&self) -> Self {
VChild {
props: self.props.clone(),
node_ref: self.node_ref.clone(),
key: self.key.clone()
key: self.key.clone(),
}
}
}
Expand All @@ -58,8 +58,12 @@ where
COMP: Component,
{
/// Creates a child component that can be accessed and modified by its parent.
pub fn new(props: COMP::Properties, node_ref: NodeRef, key:String) -> Self {
Self { props, node_ref, key }
pub fn new(props: COMP::Properties, node_ref: NodeRef, key: String) -> Self {
Self {
props,
node_ref,
key,
}
}
}

Expand Down Expand Up @@ -100,7 +104,7 @@ impl Clone for Mounted {

impl VComp {
/// This method prepares a generator to make a new instance of the `Component`.
pub fn new<COMP>(props: COMP::Properties, node_ref: NodeRef, key:String) -> Self
pub fn new<COMP>(props: COMP::Properties, node_ref: NodeRef, key: String) -> Self
where
COMP: Component,
{
Expand Down Expand Up @@ -145,7 +149,7 @@ impl VComp {
generator: Rc::new(generator),
}),
node_ref,
key
key,
}
}
}
Expand Down
46 changes: 28 additions & 18 deletions src/virtual_dom/vlist.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! This module contains fragments implementation.
use super::{VDiff, VNode, VText};
use cfg_if::cfg_if;
use std::ops::{Deref, DerefMut};
use std::collections::HashMap;
use std::ops::{Deref, DerefMut};
cfg_if! {
if #[cfg(feature = "std_web")] {
use stdweb::web::{Element, Node};
Expand All @@ -21,16 +21,14 @@ pub struct VList {
}

impl VList {

pub fn key(&self) -> String{
pub fn key(&self) -> String {
let mut key = "vlist".to_string();
for n in &self.children{
key = key+&n.key()
for n in &self.children {
key = key + &n.key()
}

key
}

}

impl Deref for VList {
Expand Down Expand Up @@ -118,31 +116,42 @@ impl VDiff for VList {

// Process children
let mut lefts = self.children.iter_mut();
if rights.first().map(|n| n.key() != String::default()).unwrap_or_default()
if rights
.first()
.map(|n| n.key() != String::default())
.unwrap_or_default()
{
let mut rights_lookup = HashMap::with_capacity(rights.len());
let mut i = 0 as usize;
for r in rights.drain(..) {
rights_lookup.insert(r.key().to_owned(), RightNode {
node: Some(r),
pos: i
});
rights_lookup.insert(
r.key().to_owned(),
RightNode {
node: Some(r),
pos: i,
},
);
i += 1;
}
loop {
match lefts.next() {
Some(left) =>{
Some(left) => {
let right = rights_lookup.get_mut(&left.key());
match right{
Some(right)=>{
previous_sibling = left.apply(parent, previous_sibling.as_ref(), right.node.take());
match right {
Some(right) => {
previous_sibling = left.apply(
parent,
previous_sibling.as_ref(),
right.node.take(),
);
}
None => {
previous_sibling = left.apply(parent, previous_sibling.as_ref(), None);
previous_sibling =
left.apply(parent, previous_sibling.as_ref(), None);
}
}
}
None => break
None => break,
}
}
for right in rights_lookup.values_mut() {
Expand All @@ -157,7 +166,8 @@ impl VDiff for VList {
loop {
match (lefts.next(), rights.next()) {
(Some(left), Some(right)) => {
previous_sibling = left.apply(parent, previous_sibling.as_ref(), Some(right));
previous_sibling =
left.apply(parent, previous_sibling.as_ref(), Some(right));
}
(Some(left), None) => {
previous_sibling = left.apply(parent, previous_sibling.as_ref(), None);
Expand Down
8 changes: 3 additions & 5 deletions src/virtual_dom/vnode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,16 @@ pub enum VNode {
VRef(Node),
}

impl VNode{

impl VNode {
pub fn key(&self) -> String {
match self{
match self {
VNode::VTag(vtag) => vtag.key.clone(),
VNode::VText(vtext) => String::default(),
VNode::VComp(vcomp) => vcomp.key.clone(),
VNode::VList(vlist) => String::default(),
VNode::VRef(vref) => String::default()
VNode::VRef(vref) => String::default(),
}
}

}

impl VDiff for VNode {
Expand Down
2 changes: 1 addition & 1 deletion src/virtual_dom/vtag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub struct VTag {
/// Keeps handler for attached listeners to have an opportunity to drop them later.
captured: Vec<EventListener>,

pub key: String
pub key: String,
}

impl Clone for VTag {
Expand Down

0 comments on commit b9bd4af

Please sign in to comment.