on master help sign in
Add tests for changing namespace
848215bRyan Levick
src/node.rs+5
@@ -174,6 +174,11 @@ impl<'a> ElementNode<'a> {
174 pub fn children(&self) -> &'a [Node<'a>] {
174 pub fn children(&self) -> &'a [Node<'a>] {
175 self.children
175 self.children
176 }
176 }
177+
178+ /// Get this element's namespace.
179+ pub fn namespace(&self) -> Option<&'a str> {
180+ self.namespace
181+ }
177}
182}
178
183
179union CallbackFatPtr<'a> {
184union CallbackFatPtr<'a> {
src/vdom.rs+4−4
@@ -303,19 +303,19 @@ impl VdomInnerExclusive {
303 listeners: new_listeners,
303 listeners: new_listeners,
304 attributes: new_attributes,
304 attributes: new_attributes,
305 children: new_children,
305 children: new_children,
306− namespace: _,
306+ namespace: new_namespace,
307 }),
307 }),
308 Node::Element(ElementNode {
308 Node::Element(ElementNode {
309 tag_name: old_tag_name,
309 tag_name: old_tag_name,
310 listeners: old_listeners,
310 listeners: old_listeners,
311 attributes: old_attributes,
311 attributes: old_attributes,
312 children: old_children,
312 children: old_children,
313− namespace: _,
313+ namespace: old_namespace,
314 }),
314 }),
315 ) => {
315 ) => {
316 debug!(" updating an element");
316 debug!(" updating an element");
317− if new_tag_name != old_tag_name {
317+ if new_tag_name != old_tag_name || new_namespace != old_namespace {
318− debug!(" different tag names; creating new element and replacing old element");
318+ debug!(" different tag names or namespaces; creating new element and replacing old element");
319 self.create(registry, new);
319 self.create(registry, new);
320 self.change_list.emit_replace_with();
320 self.change_list.emit_replace_with();
321 return;
321 return;
tests/web/main.rs+3
@@ -92,6 +92,9 @@ pub fn assert_rendered<R: Render>(container: &web_sys::Element, r: &R) {
92 .expect("`actual` should be an `Element`");
92 .expect("`actual` should be an `Element`");
93 check_attributes(actual.attributes(), elem.attributes());
93 check_attributes(actual.attributes(), elem.attributes());
94 check_children(actual.child_nodes(), elem.children());
94 check_children(actual.child_nodes(), elem.children());
95+ if let Some(namespace) = elem.namespace() {
96+ assert_eq!(actual.namespace_uri(), Some(namespace.into()))
97+ }
95 }
98 }
96 }
99 }
97 }
100 }
tests/web/render.rs+13
@@ -240,4 +240,17 @@ before_after! {
240 .finish()
240 .finish()
241 }
241 }
242 }
242 }
243+
244+ same_tag_different_namespace {
245+ before(bump) {
246+ div(bump)
247+ .namespace(Some("http://example.com"))
248+ .finish()
249+ }
250+ after(bump) {
251+ div(bump)
252+ .namespace(Some("http://example.net"))
253+ .finish()
254+ }
255+ }
243}
256}