Skip to content

Fixed custom elements patching, Added El::is_custom() #328

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

Merged
merged 1 commit into from
Jan 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
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