fix: add ns param for removeAttribute

This commit is contained in:
Shuanghui Yan 2022-02-22 23:14:11 +08:00
parent d19ae3ff56
commit 4eeb3da8c9
4 changed files with 23 additions and 11 deletions

View file

@ -107,6 +107,7 @@ pub enum DomEdit<'bump> {
RemoveAttribute {
root: u64,
name: &'static str,
ns: Option<&'bump str>,
},
}
@ -218,8 +219,17 @@ impl<'a> Mutations<'a> {
}
pub(crate) fn remove_attribute(&mut self, attribute: &Attribute, root: u64) {
let name = attribute.name;
self.edits.push(RemoveAttribute { name, root });
let Attribute {
name,
namespace,
..
} = attribute;
self.edits.push(RemoveAttribute {
name,
ns: *namespace,
root
});
}
pub(crate) fn mark_dirty_scope(&mut self, scope: ScopeId) {

View file

@ -63,5 +63,5 @@ extern "C" {
);
#[wasm_bindgen(method)]
pub fn RemoveAttribute(this: &Interpreter, root: u64, field: &str);
pub fn RemoveAttribute(this: &Interpreter, root: u64, field: &str, ns: Option<&str>);
}

View file

@ -105,7 +105,7 @@ export class Interpreter {
if (ns === "style") {
// @ts-ignore
node.style[name] = value;
} else if (ns != null || ns != undefined) {
} else if (ns !== null || ns !== undefined) {
node.setAttributeNS(ns, name, value);
} else {
switch (name) {
@ -133,10 +133,12 @@ export class Interpreter {
}
}
}
RemoveAttribute(root, name) {
RemoveAttribute(root, field, ns) {
const name = field;
const node = this.nodes[root];
if (name === "value") {
if (ns !== null || ns !== undefined) {
node.removeAttributeNS(ns, name);
} else if (name === "value") {
node.value = "";
} else if (name === "checked") {
node.checked = false;
@ -260,7 +262,7 @@ export class Interpreter {
}
}
if (realId == null) {
if (realId === null) {
return;
}
window.ipc.postMessage(
@ -281,7 +283,7 @@ export class Interpreter {
this.SetAttribute(edit.root, edit.field, edit.value, edit.ns);
break;
case "RemoveAttribute":
this.RemoveAttribute(edit.root, edit.name);
this.RemoveAttribute(edit.root, edit.name, edit.ns);
break;
}
}

View file

@ -127,8 +127,8 @@ impl WebsysDom {
self.interpreter.RemoveEventListener(root, event)
}
DomEdit::RemoveAttribute { root, name } => {
self.interpreter.RemoveAttribute(root, name)
DomEdit::RemoveAttribute { root, name, ns } => {
self.interpreter.RemoveAttribute(root, name, ns)
}
DomEdit::CreateTextNode { text, root } => {