-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Fix wrong order of classes when reordering or adding classes to the front #927
Conversation
Thanks for the quick turn around on this PR @LiquidBlock! What do you think about using |
That would propably result in faster and less code. I'll give it a try. |
There is a comment in the code at https://github.com/yewstack/yew/blob/master/src/virtual_dom/vtag.rs#L158-L160. /// Adds attribute to a virtual node. Not every attribute works when
/// it set as attribute. We use workarounds for:
/// `class`, `type/kind`, `value` and `checked`. Does this mean, that there might be (or have been) complications with |
@@ -136,6 +136,12 @@ impl<T: AsRef<str>> From<Vec<T>> for Classes { | |||
} | |||
} | |||
|
|||
impl PartialEq for Classes { | |||
fn eq(&self, other: &Self) -> bool { | |||
self.set.len() == other.set.len() && self.set.iter().eq(other.set.iter()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, did your tests catch this? Pretty odd that IndexSet
's equality implementation isn't transitive
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My tests did not catch this, but the vtag implementation did not use the PartialEq
trait of Classes
.
Instead it compared the inner classes.set, but since diff_classes(...)
also needs to check if the classes changed, i moved the ordered equal check to the PartialEq
trait of Classes
.
Good catch, I wasn't aware of the inconsistency of browser support for As far as I can tell, it's only IE that doesn't work well with |
The absent of |
I think that's a great idea |
An implementation with 2 test cases which should fix #926.
I also replaced
set_attribute
andremove_attribute
with their stdweb equivalents.Unfortunately the iterator of
indexmap::set::IndexSet
is not fused, this might create some overhead.This fix might introduce more updates (add, remove) to the class_list.