Nobody is happy with how the whole DOM inheritance thing has turned out,
with the verbose callbacks like abstract.with_imm_elem(|elem|
elem.SetAttribute(...)). I'm planning to improve the status quo a bit in
two ways - by switching from callbacks to returning borrowed pointers,
and by performing some renaming. We'll be looking at code like this:
fn foo(mut node: NodeRef<ScriptView>) {
println!("{}", node.node().first_child.is_some());
let other = @Node::new(DoctypeNodeTypeId);
let abstract = NodeRef::as_abstract_node(other);
node.mut_node().AppendChild(abstract);
println!("{}", node.node().first_child.is_some());
}
fn foo_elem(element: &mut Element) {
println!("{}", element.GetAttribute(~"foo").is_some());
element.SetAttribute(~"foo", ~"bar");
println!("{}", element.GetAttribute(~"foo").is_some());
}
fn main() {
let node = @Node::new(TextNodeTypeId);
let abstract = NodeRef::as_abstract_node(node);
foo(abstract);
let elem = @Element::new(HTMLUnknownElementTypeId);
let abstract_elem = NodeRef<View>::as_abstract_node(elem);
foo_elem(abstract_elem.mut_element());
}
We can pass around pointers to concrete types, or opaque references that
can easily be used to obtain concrete types (in a fashion that asserts
if it's used incorrectly). Names like AbstractFoo will become FooRef,
and we can change the verbose names like abstract_self to self_ref.
I welcome any feedback or concerns about this change. The actual
mechanics are no different than before; we insist that all derived types
store their parent type in the first field so we can safely cast between
them.
Cheers,
Josh
_______________________________________________
dev-servo mailing list
dev-servo@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-servo