Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement PartialEq for VChild #1242

Merged
merged 2 commits into from
May 17, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 45 additions & 1 deletion yew/src/virtual_dom/vcomp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ impl<COMP: Component> Clone for VChild<COMP> {
}
}

impl<COMP: Component> PartialEq for VChild<COMP>
where
COMP::Properties: PartialEq,
{
fn eq(&self, other: &VChild<COMP>) -> bool {
self.props == other.props
}
}

impl<COMP> VChild<COMP>
where
COMP: Component,
Expand Down Expand Up @@ -325,8 +334,9 @@ impl<COMP: Component> fmt::Debug for VChild<COMP> {

#[cfg(test)]
mod tests {
use super::VChild;
use crate::macros::Properties;
use crate::{html, Component, ComponentLink, Html, ShouldRender};
use crate::{html, Component, ComponentLink, Html, NodeRef, ShouldRender};
#[cfg(feature = "wasm_test")]
use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure};

Expand Down Expand Up @@ -391,4 +401,38 @@ mod tests {
<Comp with props />
};
}

#[test]
fn vchild_partialeq() {
let vchild1: VChild<Comp> = VChild::new(
Props {
field_1: 1,
field_2: 1,
},
NodeRef::default(),
None,
);

let vchild2: VChild<Comp> = VChild::new(
Props {
field_1: 1,
field_2: 1,
},
NodeRef::default(),
None,
);

let vchild3: VChild<Comp> = VChild::new(
Props {
field_1: 2,
field_2: 2,
},
NodeRef::default(),
None,
);

assert_eq!(vchild1, vchild2);
assert_ne!(vchild1, vchild3);
assert_ne!(vchild2, vchild3);
}
}