Skip to content

Commit

Permalink
fix: Custom elements patching, Add El::is_custom()
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinKavik committed Jan 4, 2020
1 parent e1adbea commit 38ab79d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
[unreleased]

- Implemented `UpdateEl` for `Filter` and `FilterMap`.
- Added method `El::is_custom(&self)`.
- Fixed custom elements patching (#325).

## v0.5.1
- [BREAKING] `MessageMapper::map_message` changed to `MessageMapper::map_msg`.
Expand Down
10 changes: 10 additions & 0 deletions src/virtual_dom/node/el.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,16 @@ impl<Ms> El<Ms> {
child.strip_ws_nodes_from_self_and_children();
}
}

/// Is it a custom element?
pub fn is_custom(&self) -> bool {
// @TODO: replace with `matches!` macro once stable
if let Tag::Custom(_) = self.tag {
true
} else {
false
}
}
}

/// Allow the user to clone their Els. Note that there's no easy way to clone the
Expand Down
3 changes: 2 additions & 1 deletion src/virtual_dom/patch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,9 @@ fn patch_el<'a, Ms, Mdl, ElC: View<Ms>, GMs>(
// old el vdom's elements are still attached.

// Namespaces can't be patched, since they involve create_element_ns instead of create_element.
// Custom elements can't be patched, because we need to reinit them (Issue #325). (@TODO is there a better way?)
// Something about this element itself is different: patch it.
if old.tag != new.tag || old.namespace != new.namespace {
if old.tag != new.tag || old.namespace != new.namespace || old.is_custom() {
let old_el_ws = old.node_ws.as_ref().expect("Missing websys el");

// We don't use assign_nodes directly here, since we only have access to
Expand Down

0 comments on commit 38ab79d

Please # to comment.