|
@@ -5,14 +5,10 @@
|
|
|
|
|
|
use crate::{
|
|
use crate::{
|
|
events::VirtualEvent,
|
|
events::VirtualEvent,
|
|
- innerlude::{Context, NodeCtx, Properties, ScopeIdx, FC},
|
|
|
|
|
|
+ innerlude::{Context, Properties, ScopeIdx, FC},
|
|
};
|
|
};
|
|
-
|
|
|
|
use bumpalo::Bump;
|
|
use bumpalo::Bump;
|
|
-use std::fmt::Debug;
|
|
|
|
-use std::sync::Arc;
|
|
|
|
-use std::{any::Any, cell::RefCell, marker::PhantomData};
|
|
|
|
-type Rc<T> = Arc<T>;
|
|
|
|
|
|
+use std::{cell::RefCell, fmt::Debug, marker::PhantomData, rc::Rc};
|
|
|
|
|
|
/// A domtree represents the result of "Viewing" the context
|
|
/// A domtree represents the result of "Viewing" the context
|
|
/// It's a placeholder over vnodes, to make working with lifetimes easier
|
|
/// It's a placeholder over vnodes, to make working with lifetimes easier
|
|
@@ -21,25 +17,16 @@ pub struct DomTree {
|
|
pub(crate) root: VNode<'static>,
|
|
pub(crate) root: VNode<'static>,
|
|
}
|
|
}
|
|
|
|
|
|
-// ==============================
|
|
|
|
-// VNODES
|
|
|
|
-// ==============================
|
|
|
|
-
|
|
|
|
/// Tools for the base unit of the virtual dom - the VNode
|
|
/// Tools for the base unit of the virtual dom - the VNode
|
|
/// VNodes are intended to be quickly-allocated, lightweight enum values.
|
|
/// VNodes are intended to be quickly-allocated, lightweight enum values.
|
|
///
|
|
///
|
|
/// Components will be generating a lot of these very quickly, so we want to
|
|
/// Components will be generating a lot of these very quickly, so we want to
|
|
/// limit the amount of heap allocations / overly large enum sizes.
|
|
/// limit the amount of heap allocations / overly large enum sizes.
|
|
-#[derive(Debug)]
|
|
|
|
pub enum VNode<'src> {
|
|
pub enum VNode<'src> {
|
|
/// An element node (node type `ELEMENT_NODE`).
|
|
/// An element node (node type `ELEMENT_NODE`).
|
|
Element(&'src VElement<'src>),
|
|
Element(&'src VElement<'src>),
|
|
|
|
|
|
/// A text node (node type `TEXT_NODE`).
|
|
/// A text node (node type `TEXT_NODE`).
|
|
- ///
|
|
|
|
- /// Note: This wraps a `VText` instead of a plain `String` in
|
|
|
|
- /// order to enable custom methods like `create_text_node()` on the
|
|
|
|
- /// wrapped type.
|
|
|
|
Text(VText<'src>),
|
|
Text(VText<'src>),
|
|
|
|
|
|
/// A "suspended component"
|
|
/// A "suspended component"
|
|
@@ -101,7 +88,6 @@ impl<'a> VNode<'a> {
|
|
// ========================================================
|
|
// ========================================================
|
|
// VElement (div, h1, etc), attrs, keys, listener handle
|
|
// VElement (div, h1, etc), attrs, keys, listener handle
|
|
// ========================================================
|
|
// ========================================================
|
|
-#[derive(Debug)]
|
|
|
|
pub struct VElement<'a> {
|
|
pub struct VElement<'a> {
|
|
/// Elements have a tag name, zero or more attributes, and zero or more
|
|
/// Elements have a tag name, zero or more attributes, and zero or more
|
|
pub key: NodeKey<'a>,
|
|
pub key: NodeKey<'a>,
|
|
@@ -112,20 +98,6 @@ pub struct VElement<'a> {
|
|
pub namespace: Option<&'a str>,
|
|
pub namespace: Option<&'a str>,
|
|
}
|
|
}
|
|
|
|
|
|
-impl<'a> VElement<'a> {
|
|
|
|
- // The tag of a component MUST be known at compile time
|
|
|
|
- pub fn new(_tag: &'a str) -> Self {
|
|
|
|
- todo!()
|
|
|
|
- // VElement {
|
|
|
|
- // tag,
|
|
|
|
- // attrs: HashMap::new(),
|
|
|
|
- // events: HashMap::new(),
|
|
|
|
- // // events: Events(HashMap::new()),
|
|
|
|
- // children: vec![],
|
|
|
|
- // }
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
/// An attribute on a DOM node, such as `id="my-thing"` or
|
|
/// An attribute on a DOM node, such as `id="my-thing"` or
|
|
/// `href="https://example.com"`.
|
|
/// `href="https://example.com"`.
|
|
#[derive(Clone, Debug)]
|
|
#[derive(Clone, Debug)]
|
|
@@ -174,18 +146,9 @@ pub struct Listener<'bump> {
|
|
pub scope: ScopeIdx,
|
|
pub scope: ScopeIdx,
|
|
pub id: usize,
|
|
pub id: usize,
|
|
|
|
|
|
- // pub(crate) _i: &'bump str,
|
|
|
|
- // #[serde(skip_serializing, skip_deserializing, default="")]
|
|
|
|
- // /// The callback to invoke when the event happens.
|
|
|
|
|
|
+ /// The callback to invoke when the event happens.
|
|
pub(crate) callback: &'bump (dyn Fn(VirtualEvent)),
|
|
pub(crate) callback: &'bump (dyn Fn(VirtualEvent)),
|
|
}
|
|
}
|
|
-impl Debug for Listener<'_> {
|
|
|
|
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
- f.debug_struct("Listener")
|
|
|
|
- .field("event", &self.event)
|
|
|
|
- .finish()
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
|
|
|
|
/// The key for keyed children.
|
|
/// The key for keyed children.
|
|
///
|
|
///
|
|
@@ -263,12 +226,6 @@ pub struct VComponent<'src> {
|
|
_p: PhantomData<&'src ()>,
|
|
_p: PhantomData<&'src ()>,
|
|
}
|
|
}
|
|
|
|
|
|
-impl std::fmt::Debug for VComponent<'_> {
|
|
|
|
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
- Ok(())
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
impl<'a> VComponent<'a> {
|
|
impl<'a> VComponent<'a> {
|
|
// use the type parameter on props creation and move it into a portable context
|
|
// use the type parameter on props creation and move it into a portable context
|
|
// this lets us keep scope generic *and* downcast its props when we need to:
|
|
// this lets us keep scope generic *and* downcast its props when we need to:
|