Skip to content

Commit

Permalink
Fix replacing of text nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
dbrgn committed Feb 14, 2019
1 parent c5b94fc commit dd4c6f1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
1 change: 1 addition & 0 deletions crates/virtual-dom-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ features = [
"Node",
"NodeList",
"Text",
"CharacterData",
"Window",
]

Expand Down
15 changes: 9 additions & 6 deletions crates/virtual-dom-rs/src/patch/apply_patches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::collections::HashMap;
use std::collections::HashSet;

use wasm_bindgen::JsCast;
use web_sys::{Element, Node, Text};
use web_sys::{Element, Node, Text, CharacterData};

/// Apply all of the patches to our old root node in order to create the new root node
/// that we desire.
Expand Down Expand Up @@ -165,8 +165,8 @@ fn apply_element_patch(node: &Element, patch: &Patch) {
}
}
Patch::ChangeText(_node_idx, _new_node) => unreachable!(
"Elements should not receive ChangeText patches. Those should go to Node's"
),
"Elements should not receive ChangeText patches."
)
}
}

Expand All @@ -175,9 +175,12 @@ fn apply_text_patch(node: &Text, patch: &Patch) {
Patch::ChangeText(_node_idx, new_node) => {
node.set_node_value(Some(&new_node.text));
}
Patch::Replace(_node_idx, new_node) => {
node.replace_with_with_node_1(&new_node.create_dom_node().node)
.expect("Replacing node failed");
}
other => unreachable!(
"Nodes should only receive change text patches, not {:?}.
All other patches go to Elements", other,
),
"Text nodes should only receive ChangeText or Replace patches, not {:?}.", other,
)
}
}

0 comments on commit dd4c6f1

Please sign in to comment.