use crate::innerlude::VProps; use crate::{any_props::BoxedAnyProps, innerlude::ScopeState}; use crate::{arena::ElementId, Element, Event}; use crate::{ innerlude::{ElementRef, EventHandler, MountId}, properties::ComponentFunction, }; use crate::{Properties, VirtualDom}; use core::panic; use std::ops::Deref; use std::rc::Rc; use std::vec; use std::{ any::{Any, TypeId}, cell::Cell, fmt::{Arguments, Debug}, }; pub type TemplateId = &'static str; /// The actual state of the component's most recent computation /// /// Because Dioxus accepts components in the form of `async fn() -> Result`, we need to support both /// sync and async versions. /// /// Dioxus will do its best to immediately resolve any async components into a regular Element, but as an implementor /// you might need to handle the case where there's no node immediately ready. pub enum RenderReturn { /// A currently-available element Ready(VNode), /// The component aborted rendering early. It might've thrown an error. /// /// In its place we've produced a placeholder to locate its spot in the dom when it recovers. Aborted(VNode), } impl Clone for RenderReturn { fn clone(&self) -> Self { match self { RenderReturn::Ready(node) => RenderReturn::Ready(node.clone_mounted()), RenderReturn::Aborted(node) => RenderReturn::Aborted(node.clone_mounted()), } } } impl Default for RenderReturn { fn default() -> Self { RenderReturn::Aborted(VNode::placeholder()) } } impl Deref for RenderReturn { type Target = VNode; fn deref(&self) -> &Self::Target { match self { RenderReturn::Ready(node) | RenderReturn::Aborted(node) => node, } } } /// The information about the #[derive(Debug)] pub(crate) struct VNodeMount { /// The parent of this node pub parent: Option, /// A back link to the original node pub node: VNode, /// The IDs for the roots of this template - to be used when moving the template around and removing it from /// the actual Dom pub root_ids: Box<[ElementId]>, /// The element in the DOM that each attribute is mounted to pub(crate) mounted_attributes: Box<[ElementId]>, /// For components: This is the ScopeId the component is mounted to /// For other dynamic nodes: This is element in the DOM that each dynamic node is mounted to pub(crate) mounted_dynamic_nodes: Box<[usize]>, } /// A reference to a template along with any context needed to hydrate it /// /// The dynamic parts of the template are stored separately from the static parts. This allows faster diffing by skipping /// static parts of the template. #[derive(Debug)] pub struct VNodeInner { /// The key given to the root of this template. /// /// In fragments, this is the key of the first child. In other cases, it is the key of the root. pub key: Option, /// The static nodes and static descriptor of the template pub template: Cell