get compiling

This commit is contained in:
Jonathan Kelley committed 2024-01-11 16:51:18 -08:00
1 parent 2ae3241cc0
commit 8c94f0bc4a
18 files changed
+325 -344

No files matched your search

+1 -46
View File
@@ -568,51 +568,6 @@ pub enum TemplateAttribute {
},
}
/// An attribute with information about its position in the DOM and the element it was mounted to
#[derive(Debug)]
pub struct MountedAttribute<'a> {
pub(crate) ty: AttributeType<'a>,
/// The element in the DOM that this attribute belongs to
pub(crate) mounted_element: Cell<ElementId>,
}
impl<'a> From<Attribute<'a>> for MountedAttribute<'a> {
fn from(attr: Attribute<'a>) -> Self {
Self {
ty: AttributeType::Single(attr),
mounted_element: Default::default(),
}
}
}
impl<'a> From<&'a [Attribute<'a>]> for MountedAttribute<'a> {
fn from(attr: &'a [Attribute<'a>]) -> Self {
Self {
ty: AttributeType::Many(attr),
mounted_element: Default::default(),
}
}
}
impl<'a> From<&'a Vec<Attribute<'a>>> for MountedAttribute<'a> {
fn from(attr: &'a Vec<Attribute<'a>>) -> Self {
attr.as_slice().into()
}
}
impl<'a> MountedAttribute<'a> {
/// Get the type of this attribute
pub fn attribute_type(&self) -> &AttributeType<'a> {
&self.ty
}
/// Get the element that this attribute is mounted to
pub fn mounted_element(&self) -> ElementId {
self.mounted_element.get()
}
}
/// An attribute on a DOM node, such as `id="my-thing"` or `href="https://example.com"`
#[derive(Debug)]
pub struct Attribute {
@@ -928,7 +883,7 @@ pub trait HasAttributes<'a> {
self,
name: &'a str,
ns: Option<&'static str>,
attr: impl IntoAttributeValue<'a>,
attr: impl IntoAttributeValue,
volatile: bool,
) -> Self;
}
+2 -2
View File
@@ -391,13 +391,13 @@ impl ScopeId {
}
/// Spawn a future on a component given its [`ScopeId`].
pub fn spawn_at(fut: impl Future<Output = ()> + 'static, scope_id: ScopeId) -> Option<TaskId> {
pub fn spawn_at(fut: impl Future<Output = ()> + 'static, scope_id: ScopeId) -> Option<Task> {
with_runtime(|rt| rt.get_context(scope_id).unwrap().push_future(fut))
}
/// Spawn a future that Dioxus won't clean up when this component is unmounted
///
/// This is good for tasks that need to be run after the component has been dropped.
pub fn spawn_forever(fut: impl Future<Output = ()> + 'static) -> Option<TaskId> {
pub fn spawn_forever(fut: impl Future<Output = ()> + 'static) -> Option<Task> {
spawn_at(fut, ScopeId(0))
}
-1
View File
@@ -41,7 +41,6 @@ pub struct ScopeState {
impl Drop for ScopeState {
fn drop(&mut self) {
self.drop_listeners();
self.runtime.remove_context(self.context_id);
}
}
+37 -62
View File
@@ -338,6 +338,7 @@ impl VirtualDom {
/// It is up to the listeners themselves to mark nodes as dirty.
///
/// If you have multiple events, you can call this method multiple times before calling "render_with_deadline"
pub fn handle_event(
&mut self,
name: &str,
@@ -394,14 +395,17 @@ impl VirtualDom {
let this_path = node_template.attr_paths[idx];
// Remove the "on" prefix if it exists, TODO, we should remove this and settle on one
if target_path.is_decendant(&this_path) {
attr.ty.for_each(|attribute| {
if attribute.name.trim_start_matches("on") == name {
if let AttributeValue::Listener(listener) = &attribute.value {
listeners.push(listener);
}
}
});
if attr.name.trim_start_matches("on") == name
&& target_path.is_decendant(&this_path)
{
listeners.push(&attr.value);
// Break if this is the exact target element.
// This means we won't call two listeners with the same name on the same element. This should be
// documented, or be rejected from the rsx! macro outright
if target_path == this_path {
break;
}
}
}
@@ -413,67 +417,38 @@ impl VirtualDom {
listener.call(uievent.clone());
self.runtime.rendering.set(true);
// let origin: ScopeId = path.scope;
// self.runtime.scope_stack.borrow_mut().push(origin);
// self.runtime.rendering.set(false);
// if let Some(cb) = listener.borrow_mut().as_deref_mut() {
// cb(uievent.clone());
// }
// self.runtime.scope_stack.borrow_mut().pop();
// self.runtime.rendering.set(true);
if !uievent.propagates.get() {
return;
}
}
}
let mount = el_ref.mount.get().as_usize();
parent_node = mount.and_then(|id| self.mounts.get(id).and_then(|el| el.parent));
let mount = el_ref.mount.get().as_usize();
parent_node = mount.and_then(|id| self.mounts.get(id).and_then(|el| el.parent));
}
} else {
// Otherwise, we just call the listener on the target element
if let Some(path) = parent_node {
let el_ref = &self.mounts[path.mount.0].node;
let node_template = el_ref.template.get();
let target_path = path.path;
for (idx, attr) in el_ref.dynamic_attrs.iter().enumerate() {
let this_path = node_template.attr_paths[idx];
// Remove the "on" prefix if it exists, TODO, we should remove this and settle on one
// Only call the listener if this is the exact target element.
if attr.name.trim_start_matches("on") == name && target_path == this_path {
if let AttributeValue::Listener(listener) = &attr.value {
self.runtime.rendering.set(false);
listener.call(uievent.clone());
self.runtime.rendering.set(true);
break;
}
}
}
}
// else {
// // Otherwise, we just call the listener on the target element
// if let Some(path) = parent_node {
// let el_ref = &self.mounts[path.mount.0].node;
// let node_template = el_ref.template.get();
// let target_path = path.path;
// for (idx, attr) in el_ref.dynamic_attrs.iter().enumerate() {
// let this_path = node_template.attr_paths[idx];
// // Remove the "on" prefix if it exists, TODO, we should remove this and settle on one
// // Only call the listener if this is the exact target element.
// if attr.name.trim_start_matches("on") == name && target_path == this_path {
// if let AttributeValue::Listener(listener) = &attr.value {
// self.runtime.rendering.set(false);
// listener.call(uievent.clone());
// self.runtime.rendering.set(true);
// // if target_path == this_path {
// // let mut should_stop = false;
// // attr.ty.for_each(|attribute| {
// // if attribute.name.trim_start_matches("on") == name {
// // if let AttributeValue::Listener(listener) = &attribute.value {
// // let origin = path.scope;
// // self.runtime.scope_stack.borrow_mut().push(origin);
// // self.runtime.rendering.set(false);
// // if let Some(cb) = listener.borrow_mut().as_deref_mut() {
// // cb(uievent.clone());
// // }
// // self.runtime.scope_stack.borrow_mut().pop();
// // self.runtime.rendering.set(true);
// should_stop = true;
// }
// }
// // });
// if should_stop {
// return;
// }
// }
// }
// }
}
}