mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-30 08:00:21 +00:00
remove attributes with the None value
This commit is contained in:
parent
cb2d672105
commit
ea43b864db
3 changed files with 34 additions and 26 deletions
|
@ -144,8 +144,15 @@ class Interpreter {
|
||||||
this.nodes[root].textContent = text;
|
this.nodes[root].textContent = text;
|
||||||
}
|
}
|
||||||
SetAttribute(id, field, value, ns) {
|
SetAttribute(id, field, value, ns) {
|
||||||
const node = this.nodes[id];
|
console.log("set attribute", id, field, value, ns);
|
||||||
this.SetAttributeInner(node, field, value, ns);
|
|
||||||
|
if (value === null) {
|
||||||
|
this.RemoveAttribute(id, field, ns);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const node = this.nodes[id];
|
||||||
|
this.SetAttributeInner(node, field, value, ns);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
SetAttributeInner(node, field, value, ns) {
|
SetAttributeInner(node, field, value, ns) {
|
||||||
const name = field;
|
const name = field;
|
||||||
|
@ -334,9 +341,6 @@ class Interpreter {
|
||||||
case "SetAttribute":
|
case "SetAttribute":
|
||||||
this.SetAttribute(edit.id, edit.name, edit.value, edit.ns);
|
this.SetAttribute(edit.id, edit.name, edit.value, edit.ns);
|
||||||
break;
|
break;
|
||||||
case "SetBoolAttribute":
|
|
||||||
this.SetAttribute(edit.id, edit.name, edit.value, edit.ns);
|
|
||||||
break;
|
|
||||||
case "RemoveAttribute":
|
case "RemoveAttribute":
|
||||||
this.RemoveAttribute(edit.id, edit.name, edit.ns);
|
this.RemoveAttribute(edit.id, edit.name, edit.ns);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -80,7 +80,6 @@ pub enum OwnedAttributeValue<V: FromAnyValue = ()> {
|
||||||
Int(i64),
|
Int(i64),
|
||||||
Bool(bool),
|
Bool(bool),
|
||||||
Custom(V),
|
Custom(V),
|
||||||
None,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait FromAnyValue {
|
pub trait FromAnyValue {
|
||||||
|
@ -99,7 +98,6 @@ impl<V: FromAnyValue> Debug for OwnedAttributeValue<V> {
|
||||||
Self::Int(arg0) => f.debug_tuple("Int").field(arg0).finish(),
|
Self::Int(arg0) => f.debug_tuple("Int").field(arg0).finish(),
|
||||||
Self::Bool(arg0) => f.debug_tuple("Bool").field(arg0).finish(),
|
Self::Bool(arg0) => f.debug_tuple("Bool").field(arg0).finish(),
|
||||||
Self::Custom(_) => f.debug_tuple("Any").finish(),
|
Self::Custom(_) => f.debug_tuple("Any").finish(),
|
||||||
Self::None => write!(f, "None"),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -112,7 +110,7 @@ impl<V: FromAnyValue> From<BorrowedAttributeValue<'_>> for OwnedAttributeValue<V
|
||||||
BorrowedAttributeValue::Int(int) => Self::Int(int),
|
BorrowedAttributeValue::Int(int) => Self::Int(int),
|
||||||
BorrowedAttributeValue::Bool(bool) => Self::Bool(bool),
|
BorrowedAttributeValue::Bool(bool) => Self::Bool(bool),
|
||||||
BorrowedAttributeValue::Any(any) => Self::Custom(V::from_any_value(&*any)),
|
BorrowedAttributeValue::Any(any) => Self::Custom(V::from_any_value(&*any)),
|
||||||
BorrowedAttributeValue::None => Self::None,
|
BorrowedAttributeValue::None => panic!("None attribute values result in removing the attribute, not converting it to a None value.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -146,13 +144,6 @@ impl<V: FromAnyValue> OwnedAttributeValue<V> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_none(&self) -> Option<()> {
|
|
||||||
match self {
|
|
||||||
OwnedAttributeValue::None => Some(()),
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn as_custom(&self) -> Option<&V> {
|
pub fn as_custom(&self) -> Option<&V> {
|
||||||
match self {
|
match self {
|
||||||
OwnedAttributeValue::Custom(custom) => Some(custom),
|
OwnedAttributeValue::Custom(custom) => Some(custom),
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use dioxus_core::{ElementId, Mutations, TemplateNode};
|
use dioxus_core::{BorrowedAttributeValue, ElementId, Mutations, TemplateNode};
|
||||||
use rustc_hash::{FxHashMap, FxHashSet};
|
use rustc_hash::{FxHashMap, FxHashSet};
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::ops::{Deref, DerefMut, Index, IndexMut};
|
use std::ops::{Deref, DerefMut, Index, IndexMut};
|
||||||
|
@ -264,19 +264,32 @@ impl<S: State> RealDom<S> {
|
||||||
let node_id = self.element_to_node_id(id);
|
let node_id = self.element_to_node_id(id);
|
||||||
let node = self.tree.get_mut(node_id).unwrap();
|
let node = self.tree.get_mut(node_id).unwrap();
|
||||||
if let NodeType::Element { attributes, .. } = &mut node.node_data.node_type {
|
if let NodeType::Element { attributes, .. } = &mut node.node_data.node_type {
|
||||||
attributes.insert(
|
if let BorrowedAttributeValue::None = &value {
|
||||||
OwnedAttributeDiscription {
|
attributes.remove(&OwnedAttributeDiscription {
|
||||||
name: name.to_string(),
|
name: name.to_string(),
|
||||||
namespace: ns.map(|s| s.to_string()),
|
namespace: ns.map(|s| s.to_string()),
|
||||||
volatile: false,
|
volatile: false,
|
||||||
},
|
});
|
||||||
OwnedAttributeValue::from(value),
|
mark_dirty(
|
||||||
);
|
node_id,
|
||||||
mark_dirty(
|
NodeMask::new_with_attrs(AttributeMask::single(name)),
|
||||||
node_id,
|
&mut nodes_updated,
|
||||||
NodeMask::new_with_attrs(AttributeMask::single(name)),
|
);
|
||||||
&mut nodes_updated,
|
} else {
|
||||||
);
|
attributes.insert(
|
||||||
|
OwnedAttributeDiscription {
|
||||||
|
name: name.to_string(),
|
||||||
|
namespace: ns.map(|s| s.to_string()),
|
||||||
|
volatile: false,
|
||||||
|
},
|
||||||
|
OwnedAttributeValue::from(value),
|
||||||
|
);
|
||||||
|
mark_dirty(
|
||||||
|
node_id,
|
||||||
|
NodeMask::new_with_attrs(AttributeMask::single(name)),
|
||||||
|
&mut nodes_updated,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SetText { value, id } => {
|
SetText { value, id } => {
|
||||||
|
|
Loading…
Reference in a new issue