use crate::any_props::{BoxedAnyProps, VProps}; use crate::innerlude::{ElementRef, EventHandler}; use crate::Properties; use crate::{arena::ElementId, Element, Event, ScopeId}; use std::cell::RefCell; 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(Scope) -> 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. #[derive(Clone)] 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 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, /// 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