Skip to content

Commit

Permalink
Attributes: Fix apply_diff_index_maps
Browse files Browse the repository at this point in the history
The old algorithm simply stops when key name/order changes, which
is simply wrong.

Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
  • Loading branch information
maurerdietmar committed May 4, 2022
1 parent 8d9ecf2 commit 946b439
Showing 1 changed file with 12 additions and 38 deletions.
50 changes: 12 additions & 38 deletions packages/yew/src/dom_bundle/btag/attributes.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::collections::HashMap;
use std::iter;
use std::ops::Deref;

use indexmap::IndexMap;
Expand Down Expand Up @@ -91,45 +90,20 @@ impl Attributes {
new: &IndexMap<AttrValue, AttrValue>,
old: &IndexMap<AttrValue, AttrValue>,
) {
let mut old_iter = old.iter();
let mut new_iter = new.iter();
loop {
match (new_iter.next(), old_iter.next()) {
(Some((new_key, new_value)), Some((old_key, old_value))) => {
if new_key != old_key {
break;
for (key, value) in new.iter() {
match old.get(key) {
Some(old_value) => {
if value != old_value {
Self::set_attribute(el, key, value);
}
if new_value != old_value {
Self::set_attribute(el, new_key, new_value);
}
}
// new attributes
(Some(attr), None) => {
for (key, value) in iter::once(attr).chain(new_iter) {
match old.get(key) {
Some(old_value) => {
if value != old_value {
Self::set_attribute(el, key, value);
}
}
None => {
Self::set_attribute(el, key, value);
}
}
}
break;
}
// removed attributes
(None, Some(attr)) => {
for (key, _) in iter::once(attr).chain(old_iter) {
let key = key;
if !new.contains_key(key) {
Self::remove_attribute(el, key);
}
}
break;
}
(None, None) => break,
None => Self::set_attribute(el, key, value),
}
}

for (key, _value) in old.iter() {
if !new.contains_key(key) {
Self::remove_attribute(el, key);
}
}
}
Expand Down

0 comments on commit 946b439

Please sign in to comment.