Skip to content

Commit

Permalink
Remove props cloning
Browse files Browse the repository at this point in the history
  • Loading branch information
jstarry committed Dec 8, 2019
1 parent 745e7f9 commit 1acb041
Show file tree
Hide file tree
Showing 18 changed files with 52 additions and 54 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ Properties are also pure Rust types with strict type-checking during the compila
```rust
// my_button.rs

#[derive(Clone, Properties, PartialEq)]
#[derive(Properties, PartialEq)]
pub struct Properties {
pub hidden: bool,
#[props(required)]
Expand Down
2 changes: 1 addition & 1 deletion crates/macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
//! link: ComponentLink<Self>,
//! }
//!
//! #[derive(Clone, Properties)]
//! #[derive(Properties)]
//! struct Props {
//! #[props(required)]
//! prop: String,
Expand Down
2 changes: 1 addition & 1 deletion examples/custom_components/src/barrier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub enum Msg {
ChildClicked,
}

#[derive(Clone, PartialEq, Properties)]
#[derive(PartialEq, Properties)]
pub struct Props {
pub limit: u32,
#[props(required)]
Expand Down
2 changes: 1 addition & 1 deletion examples/custom_components/src/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub enum Msg {
Clicked,
}

#[derive(Clone, PartialEq, Properties)]
#[derive(PartialEq, Properties)]
pub struct Props {
pub title: String,
#[props(required)]
Expand Down
2 changes: 1 addition & 1 deletion examples/custom_components/src/counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub enum Msg {
Increase,
}

#[derive(Clone, PartialEq, Properties)]
#[derive(PartialEq, Properties)]
pub struct Props {
pub initial: u32,
pub color: Color,
Expand Down
2 changes: 1 addition & 1 deletion examples/large_table/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl Component for Model {
fn view(&self) -> Html {
html! {
<table>
{ (0..99).map(|row| self.view_row(row)).collect::<Html<Self>>() }
{ (0..99).map(|row| self.view_row(row)).collect::<Html>() }
</table>
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/node_refs/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub struct InputComponent {
link: ComponentLink<Self>,
}

#[derive(Clone, Properties)]
#[derive(Properties)]
pub struct Props {
#[props(required)]
pub on_hover: Callback<()>,
Expand Down
12 changes: 6 additions & 6 deletions src/html/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub type Html = VNode;
/// In this example, the `Wrapper` component is used to wrap other elements.
/// ```
///# use yew::{Children, Html, Properties, Component, ComponentLink, html};
///# #[derive(Clone, Properties)]
///# #[derive(Properties)]
///# struct WrapperProps {
///# children: Children,
///# }
Expand Down Expand Up @@ -95,7 +95,7 @@ pub type Html = VNode;
/// children property can be used to render the wrapped elements.
/// ```
///# use yew::{Children, Html, Properties, Renderable, Component, ComponentLink, html};
/// #[derive(Clone, Properties)]
/// #[derive(Properties)]
/// struct WrapperProps {
/// children: Children,
/// }
Expand Down Expand Up @@ -127,7 +127,7 @@ pub type Children = ChildrenRenderer<Html>;
/// ```
///# use yew::{html, Component, Renderable, Html, ComponentLink, ChildrenWithProps, Properties};
///#
///# #[derive(Clone, Properties)]
///# #[derive(Properties)]
///# struct ListProps {
///# children: ChildrenWithProps<ListItem>,
///# }
Expand All @@ -139,7 +139,7 @@ pub type Children = ChildrenRenderer<Html>;
///# fn update(&mut self, msg: Self::Message) -> bool {unimplemented!()}
///# fn view(&self) -> Html {unimplemented!()}
///# }
///# #[derive(Clone, Properties)]
///# #[derive(Properties)]
///# struct ListItemProps {
///# value: String
///# }
Expand Down Expand Up @@ -169,7 +169,7 @@ pub type Children = ChildrenRenderer<Html>;
/// ```
///# use yew::{html, Component, Html, ChildrenWithProps, ComponentLink, Properties};
///#
/// #[derive(Clone, Properties)]
/// #[derive(Properties)]
/// struct ListProps {
/// children: ChildrenWithProps<ListItem>,
/// }
Expand All @@ -191,7 +191,7 @@ pub type Children = ChildrenRenderer<Html>;
/// }
/// }
///#
///# #[derive(Clone, Properties)]
///# #[derive(Properties)]
///# struct ListItemProps {
///# value: String
///# }
Expand Down
4 changes: 2 additions & 2 deletions src/virtual_dom/vtag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,14 @@ impl VTag {

/// Adds new listener to the node.
/// It's boxed because we want to keep it in a single list.
/// Lates `Listener::attach` called to attach actual listener to a DOM node.
/// Later `Listener::attach` will attach an actual listener to a DOM node.
pub fn add_listener(&mut self, listener: Box<dyn Listener>) {
self.listeners.push(listener);
}

/// Adds new listeners to the node.
/// They are boxed because we want to keep them in a single list.
/// Lates `Listener::attach` called to attach actual listener to a DOM node.
/// Later `Listener::attach` will attach an actual listener to a DOM node.
pub fn add_listeners(&mut self, listeners: Vec<Box<dyn Listener>>) {
for listener in listeners {
self.listeners.push(listener);
Expand Down
9 changes: 4 additions & 5 deletions tests/derive_props/fail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ use yew::prelude::*;

mod t1 {
use super::*;
#[derive(Clone)]
struct Value;
#[derive(Clone, Properties)]
#[derive(Properties)]
pub struct Props {
// ERROR: optional params must implement default
value: Value,
Expand All @@ -15,7 +14,7 @@ mod t1 {

mod t2 {
use super::*;
#[derive(Clone, Properties)]
#[derive(Properties)]
pub struct Props {
// ERROR: optional is not a tag
#[props(optional)]
Expand All @@ -25,7 +24,7 @@ mod t2 {

mod t3 {
use super::*;
#[derive(Clone, Properties)]
#[derive(Properties)]
pub struct Props {
#[props(required)]
value: String,
Expand All @@ -38,7 +37,7 @@ mod t3 {

mod t4 {
use super::*;
#[derive(Clone, Properties)]
#[derive(Properties)]
pub struct Props {
b: i32,
#[props(required)]
Expand Down
26 changes: 13 additions & 13 deletions tests/derive_props/fail.stderr
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
error: expected `props(required)`
--> $DIR/fail.rs:21:11
--> $DIR/fail.rs:20:11
|
21 | #[props(optional)]
20 | #[props(optional)]
| ^^^^^

error[E0277]: the trait bound `t1::Value: std::default::Default` is not satisfied
--> $DIR/fail.rs:9:21
--> $DIR/fail.rs:8:14
|
9 | #[derive(Clone, Properties)]
| ^^^^^^^^^^ the trait `std::default::Default` is not implemented for `t1::Value`
8 | #[derive(Properties)]
| ^^^^^^^^^^ the trait `std::default::Default` is not implemented for `t1::Value`
|
= note: required by `std::default::Default::default`

error[E0599]: no method named `build` found for type `t3::PropsBuilder<t3::PropsBuilderStep_missing_required_prop_value>` in the current scope
--> $DIR/fail.rs:35:26
--> $DIR/fail.rs:34:26
|
28 | #[derive(Clone, Properties)]
| - method `build` not found for this
27 | #[derive(Properties)]
| - method `build` not found for this
...
35 | Props::builder().build();
34 | Props::builder().build();
| ^^^^^ method not found in `t3::PropsBuilder<t3::PropsBuilderStep_missing_required_prop_value>`

error[E0599]: no method named `b` found for type `t4::PropsBuilder<t4::PropsBuilderStep_missing_required_prop_a>` in the current scope
--> $DIR/fail.rs:49:26
--> $DIR/fail.rs:48:26
|
41 | #[derive(Clone, Properties)]
| - method `b` not found for this
40 | #[derive(Properties)]
| - method `b` not found for this
...
49 | Props::builder().b(1).a(2).build();
48 | Props::builder().b(1).a(2).build();
| ^ help: there is a method with a similar name: `a`
19 changes: 9 additions & 10 deletions tests/derive_props/pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use yew::prelude::*;
mod t1 {
use super::*;

#[derive(Clone, Properties)]
pub struct Props<T: Clone + Default> {
#[derive(Properties)]
pub struct Props<T: Default> {
value: T,
}

Expand All @@ -19,10 +19,9 @@ mod t1 {
mod t2 {
use super::*;

#[derive(Clone)]
struct Value;
#[derive(Clone, Properties)]
pub struct Props<T: Clone> {
#[derive(Properties)]
pub struct Props<T> {
#[props(required)]
value: T,
}
Expand All @@ -35,7 +34,7 @@ mod t2 {
mod t3 {
use super::*;

#[derive(Clone, Properties)]
#[derive(Properties)]
pub struct Props {
#[props(required)]
b: i32,
Expand All @@ -51,10 +50,10 @@ mod t3 {
mod t4 {
use super::*;

#[derive(Clone, Properties)]
#[derive(Properties)]
pub struct Props<T>
where
T: Clone + Default,
T: Default,
{
value: T,
}
Expand All @@ -68,8 +67,8 @@ mod t4 {
mod t5 {
use super::*;

#[derive(Clone, Properties)]
pub struct Props<'a, T: Clone + Default + 'a> {
#[derive(Properties)]
pub struct Props<'a, T: Default + 'a> {
static_value: &'static str,
#[props(required)]
value: &'a T,
Expand Down
6 changes: 3 additions & 3 deletions tests/macro/html-component-pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod helpers;

use yew::html::ChildrenRenderer;

#[derive(Clone, Properties, Default, PartialEq)]
#[derive(Properties, Default, PartialEq)]
pub struct ChildProperties {
pub string: String,
#[props(required)]
Expand All @@ -32,7 +32,7 @@ impl Component for Child {
}
}

#[derive(Clone, Properties, Default)]
#[derive(Properties, Default)]
pub struct ContainerProperties {
#[props(required)]
pub int: i32,
Expand All @@ -57,7 +57,7 @@ impl Component for Container {
}
}

#[derive(Clone, Properties, Default)]
#[derive(Properties, Default)]
pub struct ChildContainerProperties {
#[props(required)]
pub int: i32,
Expand Down
2 changes: 1 addition & 1 deletion tests/macro/test_component.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use yew::prelude::*;

#[derive(Clone, Properties, PartialEq)]
#[derive(Properties, PartialEq)]
pub struct TestProperties {
pub string: String,
pub int: i32,
Expand Down
2 changes: 1 addition & 1 deletion tests/vcomp_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ wasm_bindgen_test_configure!(run_in_browser);

struct Comp;

#[derive(Clone, PartialEq, Properties)]
#[derive(PartialEq, Properties)]
struct Props {
field_1: u32,
field_2: u32,
Expand Down
2 changes: 1 addition & 1 deletion tests/vlist_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn check_fragments() {
<>
</>
};
let _ = html! {
html! {
<div>
{ fragment }
</div>
Expand Down
6 changes: 3 additions & 3 deletions tests/vtag_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,9 @@ fn supports_multiple_classes_vec() {
fn filter_empty_string_classes_vec() {
let mut classes = vec![""];
classes.push("class-2");
let a: VNode<Comp> = html! { <div class=vec![""]></div> };
let b: VNode<Comp> = html! { <div class=("")></div> };
let c: VNode<Comp> = html! { <div class=""></div> };
let a = html! { <div class=vec![""]></div> };
let b = html! { <div class=("")></div> };
let c = html! { <div class=""></div> };

if let VNode::VTag(vtag) = a {
assert!(vtag.classes.is_empty());
Expand Down
4 changes: 2 additions & 2 deletions tests/vtext_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ impl Component for Comp {

#[test]
fn text_as_root() {
let _ = html! {
html! {
"Text Node As Root"
};

let _ = html! {
html! {
{ "Text Node As Root" }
};
}

0 comments on commit 1acb041

Please sign in to comment.